GuirNab
GuirNab

Reputation: 193

openIMAJ face detection - uncaught IOException

I have this method(simplified) for detecting faces(count) on images(URLs):

private int processImage(String urlString) {
    InputStream is = null;
    URLConnection resource;
    int facesCount = 0;
    try {
        resource = new URL(urlString).openConnection();
        resource.setConnectTimeout(200);
        resource.setReadTimeout(1000);
        resource.setRequestProperty("User-Agent", "Mozilla/5.0");

        String type = resource.getHeaderField("Content-Type");
        if (!type.startsWith("image/")) {
            throw new IOException("Not an image (Content-Type:" + type + ")");
        }
        is = resource.getInputStream();
        MBFImage mbfimage = ImageUtilities.readMBF(is);
        facesCount = faceDetector.detectFaces(Transforms.calculateIntensity(mbfimage)).size();
        is.close();
    } catch (IOException e) {
        System.out.println("oops");
    }
    return facesCount;
}

It works well, but if the image is somewhat corrupted (for example this test image), i get this error:

Error: Cannot decode the image for the type : Occurs in: com.sun.media.jai.opimage.CodecRIFUtil java.io.IOException: Source stream does not support seeking backwards. at com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76) at com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:40) at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88) at com.sun.media.jai.opimage.FPXRIF.create(FPXRIF.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674) at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473) at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332) at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674) at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473) at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332) at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819) at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867) at javax.media.jai.RenderedOp.getColorModel(RenderedOp.java:2242) at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2498) at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546) at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:162) at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:273) at image.ImageThread.processImage(ImageThread.java:233) at image.ImageThread.main(ImageThread.java:255) Caused by: java.lang.IllegalArgumentException: Source stream does not support seeking backwards. at com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:200) at com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:262) at com.sun.media.jai.codecimpl.fpx.StructuredStorage.getFat(StructuredStorage.java:238) at com.sun.media.jai.codecimpl.fpx.StructuredStorage.(StructuredStorage.java:131) at com.sun.media.jai.codecimpl.fpx.FPXImage.(FPXImage.java:110) at com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:38) ... 28 more

and the program hangs. I want to catch that exception, log it and go on.

Could you please help me?

Upvotes: -1

Views: 139

Answers (1)

GuirNab
GuirNab

Reputation: 193

Ok, I found the solution. I was using old version of openIMAJ (1.1.3). The latest version is 1.3.1 which works well. I didn't notice, because I overlooked the version numbers.

Upvotes: 0

Related Questions