-1

我有这种方法(简化)用于检测图像(URL)上的人脸(计数):

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;
}

它运行良好,但如果图像有些损坏(例如此测试图像),我会收到此错误:

错误:无法解码该类型的图像:发生在:com.sun.media.jai.opimage.CodecRIFUtil java.io.IOException:源流不支持向后搜索。在 com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:40) 在 com.sun.media.jai 的 com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76) .opimage.CodecRIFUtil.create(CodecRIFUtil.java:88) 在 com.sun.media.jai.opimage.FPXRIF.create(FPXRIF.java:46) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:606) 在 javax.media.jai。 FactoryCache.invoke(FactoryCache.java:

程序挂起。我想捕捉那个异常,记录它并继续。

请你帮助我好吗?

4

1 回答 1

0

好的,我找到了解决方案。我使用的是旧版本的 openIMAJ (1.1.3)。最新版本是 1.3.1,运行良好。我没有注意到,因为我忽略了版本号。

于 2015-02-18T23:53:48.700 回答