image/jpeg image processing

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

image/jpeg image processing

sammeek
Hi Benjamin,

I am trying to do some simple image processing through the WPS. The basic workflow is to get image on the client, send it to the server, perform calculations, return string result.

I have the following error:

org.n52.wps.server.ExceptionReport: Error while executing the embedded process for: pillar.automaticvalidation.LaplacePhotoBlurCheckClient
        at org.n52.wps.server.request.ExecuteRequest.call(ExecuteRequest.java:716) ~[52n-wps-server-3.3.0.jar:na]
        at org.n52.wps.server.request.ExecuteRequest.call(ExecuteRequest.java:92) ~[52n-wps-server-3.3.0.jar:na]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) ~[na:1.7.0_79]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79]
        at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
Caused by: java.lang.NullPointerException: null
        at pillar.automaticvalidation.LaplacePhotoBlurCheckClient.run(LaplacePhotoBlurCheckClient.java:65) ~[LaplacePhotoBlurCheckClient.class:na]
        at org.n52.wps.server.request.ExecuteRequest.call(ExecuteRequest.java:685) ~[52n-wps-server-3.3.0.jar:na]
        ... 5 common frames omitted


I can't seem to read in the image on the server side:

public Map<String, IData> run(Map<String, List<IData>> inputData)
                        throws ExceptionReport {

                List<IData> baseList = inputData.get("inputImage");
                List<IData> threshList = inputData.get("inputThreshold");
               
                GenericFileData data =((GenericFileDataBinding) baseList.get(0)).getPayload();
               
                File file = data.getBaseFile(true);
               
                LOG.warn("File " + file.getName() + " " + file.getTotalSpace());
               
                BufferedImage original = null;
               
                try {
                        InputStream is = new FileInputStream(file);
                        original = ImageIO.read(is);
                        //LOG.warn("IMAGE " + original.getType());
                } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        LOG.warn("Exception " + e1);
                }
               
                int threshold = ((LiteralIntBinding)threshList.get(0)).getPayload();
               
                LOG.warn("original " + original.getHeight());

The code doesn't seem to read in the file on the server side, when I retrieve the temp file from the server, it cannot be opened as an image.

client code:

 File file = new File ("1531117.jpg");
                        FileInputStream image = null;
                        try{
                        image = new FileInputStream(file);
                     
                        String threshold = ""+240;
                       
                        GenericFileData gd = new GenericFileData(image,"image/jpeg");
                       
                        inputs.put(
                                "inputImage",
                                new GenericFileDataBinding(gd)
                                );
                       

help is appreciated!!

Sam

Reply | Threaded
Open this post in threaded view
|

Re: image/jpeg image processing

BenjaminPross
Hi Sam,

I suspect this could be an issue with the encoding. If your file arrives at the server encoded in base64 (advisable for inline binary data), then you cannot directly parse it. You will have to wrap a Base64InputStream around the FileInpustream, i.e. in your example:

BufferedImage original = null;
               
try {
        InputStream is = new FileInputStream(file);

        original = ImageIO.read(new Base64InputStream(is));
...

If this doesn't help, could you try to intercept the execute request and post it here?

Cheers,

Benjamin
Reply | Threaded
Open this post in threaded view
|

Re: image/jpeg image processing

sammeek
Hi Benjamin,

I have got some of the document, but it looks like this (binary?):

?¦)ї.½Hš¾Å?øUã$Œ×>cÚä?F9?5ÕÉ?øÈ<?XW– 9*2sšö¨W•¬Œet:Ø!Áf$ƒß½i@° Ž€ä?Տ
°`qQZV¤ª…nõ–.nNì¸+—??HQϧz±?9+€IÆH?È?q?'òÅjYؾCcƒí^5WØè„T¶+$?Ü?¾ÃÞ´ìì?¸ÝÀãŒb®[Y?ÃpÆ:`VÍ¥¢‘’;u?É+·cª?VԆÇNp㞾ÜVâ[mL?Ju´*€???°äªž3šê¤·.I[S6xˆÉà{UCoæ¶?5zãÌ?ÜóSÚZ–Áۃï[V­&­?8ÓW»Aef"Q•É=0+bÞË?'¿¯?¥¶·HÀÏ'Þ®y›?»zTáèó;³Y;-?ÍRò??Ë;?·®MpúώmS;g??õéUþ'k"ÞÂR²írp?<׈½ìÓ6ZFä÷<?ö#FQV‰ç×Äò»#Òµ???Œ¡›ƒÓšä5VK¹p?å=…b.Y,M<ŽCžÕJ2[˜º¼È{ÌÅACÀ? Jr $ç­F\?œ{
cH?ظÇr(ŠL†ËQÊÙ*8Ï­]†=§z’sYQd°ç85±fK?/Ÿ^{UJ.ÖH¨«³RÂr?‡\Œ×Gm?7*?àñÒ±l´þ??OzÖµ„ÇÉ$}{S¦çGS­\šã@´hˆà?Írºß†“k2`ñÞºYî&R>byè)?›¸Š:äãZ꣙>nV‚ÊZ??â=?Á»jûð3\qS?À'9äW¸øE??¶|Ç¡¯)×tƒm3É÷p??ë_EJ¢œy‘ËZ ?‚R?;ùþTñ#mÇ?'“Š‡`?€MJª»F?#U7¥Î{;hJ?Æ:Ú–|``ScPs‚)à?\W4˜ÜtÐtj?R?°0H!F@ëM·P~ðÉ횹??ð?œþ•„çaò¶íb¹s€¿Ÿ?©’b1ŽsÅLÖdüçÜzÕyíÂð8Çz•8Ë@\Ñ'†àuî?>µ<r)?¹?¹ïYháX?sŠ•&SüG­)ÒeÆýM?}Äåˆ?ΚÒd€:UQ31
?ÿ?Z¥Lg—ëùÖ<–+žÎÖ,DØ<?olUÛuÉ???öìj’|¬0Ù?ÐV„R?Œ?Œž¹¬g©¤­Ø¼›??œcùÒ?±?EAæápHÅA$¾^1÷Msû;»?·bY&?H뚡4½Ž@?piÓJ?8''ôªÏ‚À?xÉö®št쉔\µD±ÈIäôéSÆJœƒ’{ÕXÐî8ç½^·‹<‘ŒqJvFŠOf9K?†`G_CNPÀ†ÝØ?Ôí› <{SÚ2pIÇCÅc{2bš??Üõíš?h??9ëR*v'?㱡" œûâš?Ð?RBƒÏj·??A?­$Q?Éê}ªÜQ¨äóÖ²”¯ ãw«A
¶ã»®;U¥³?–ã=©ñ?¸È?uÏqV¡dcŽ¿_JÊR{??©«¢šØ`ä&{摬\©b?µkC?mÅOöeaÏ?éM;Á½Nf[mƒ?üEU•T?x®’îÎ5AŒšÅº·\G°§ec9Åô3doâ^1ÅA#??[??jX¶©ãŽÆ©Ë?ï›n??#b?_S?U>` ?O§¥r?’';½ë°Ô¢v%—?ž?r:ò²))ø׿—½RE§fr—¼Èvc?皨T?ÅY•?q$œžÂ¡(Nr:WÕG݊:?­¥ÿÙ356718]]></ComplexData>
      </Data>
    </Input>
  </DataInputs>
</Execute>

The issue seems to be from passing the image to the server as it is OK to resolve a link on the server side and the process works. I have also tried png, your suggestion of using the base64 input reader also throws an error. I have also tried the following:

BufferedImage original = null;
               
               
                try {
               
                        BufferedImage image = ImageIO.read(data.getBaseFile(true));
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        ImageIO.write(image, "jpg", baos );
                        baos.flush();
                        byte[] imageInByte = baos.toByteArray();
                        baos.close();
                        InputStream is = new ByteArrayInputStream(imageInByte);
                       
                        original = ImageIO.read(is);

                        //original = ImageIO.read(input);
                        //LOG.warn("IMAGE " + original.getType());
                } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        LOG.warn("Exception " + e1);
                }

However it cannot read the image. I think the problem is that the file that is written as temp on the server side does not appear to contain an image.

Sam
Reply | Threaded
Open this post in threaded view
|

Re: image/jpeg image processing

BenjaminPross
In that case, I'd recommend to encode the binary as base64. Just add the encoding to the addComplexData-method, e.g.:

        executeBuilder
                        .addComplexData(
                                        inputName,
                                        data,
                                        null,
                                        "base64", "image/jpeg");

During my tests, the image file was successfully decoded and saved at server side.

Hope this helps.

Benjamin
Reply | Threaded
Open this post in threaded view
|

Re: image/jpeg image processing

sammeek
I get the following error:

Exception in thread "main" java.lang.VerifyError: (class: org/apache/commons/codec/binary/Base64InputStream, method: <init> signature: (Ljava/io/InputStream;ZI[B)V) Incompatible argument to function
        at org.n52.wps.io.datahandler.generator.AbstractGenerator.generateBase64Stream(AbstractGenerator.java:76)
        at cobweb.m24.ExecuteRequestBuilder.addComplexData(ExecuteRequestBuilder.java:140)
        at clients.test.TestClientV2.executeProcess(TestClientV2.java:330)
        at clients.test.TestClientV2.testExecute(TestClientV2.java:160)
        at clients.test.TestClientV2.main(TestClientV2.java:437)

Client side:

executeBuilder
                                    .addComplexData(
                                                    inputName,
                                                    inputData,
                                                    null,
                                                    "base64", "image/jpeg");

Server side:

GenericFileData data =((GenericFileDataBinding) baseList.get(0)).getPayload();
               
               
                File file = data.getBaseFile(true);
               
                LOG.warn("File " + file.getName() + " " + file.getTotalSpace());
               
                BufferedImage original = null;
               
               
                try {
               
                        InputStream is = new FileInputStream(file);
                       
                        original = ImageIO.read(new Base64InputStream(is));

                       
                } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        LOG.warn("Exception " + e1);
                }
       }