Ask Your Question

Revision history [back]

OpenCv Unknown exception in JNI code and then Empty JPEG image (DNL not supported)

Hello there!

I made a GUI that opens VideoCapture with opencv 2.4.6. When VideoCapture runned, it works for 2-4 sec and then Exception raises Exception in thread "Thread-3" java.lang.Exception: Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJ()}

Then I press my button to reload VideoCapture it works fine. But when I making runnable = false; there are OpenCv Error raising OpenCV Error: Unknown error code -10 (Raw image encoder error: Empty JPEG image (DNL not supported)) in unknown function, file ......\src\opencv\modules\highgui\src\grfmt_base.cpp, line 131 Exception in thread "Thread-10" CvException [org.opencv.core.CvException: ......\src\opencv\modules\highgui\src\grfmt_base.cpp:131: error: (-10) Raw image encoder error: Empty JPEG image (DNL not supported) ] at org.opencv.highgui.Highgui.imencode_1(Native Method) at org.opencv.highgui.Highgui.imencode(Highgui.java:226) at incaseqrcode.QRForm$DaemonThread.run(QRForm.java:62) at java.lang.Thread.run(Thread.java:745)

here is the code:

class DaemonThread implements Runnable { protected volatile boolean runnable = false;

    @Override
    public void run(){
        synchronized(this){
            try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException ex) {
                    Logger.getLogger(QRForm.class.getName()).log(Level.SEVERE, null, ex);
                }
            while(runnable){

                if(webSource.grab()){
                    try{
                        //;

                      if(!webSource.retrieve(frame)){
                          webSource.retrieve(frame);
                      }


                        if(Highgui.imencode(".jpg", frame, mem)){

                            Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));

                            BufferedImage buff = (BufferedImage) im;
                            Graphics g = jPanel1.getGraphics();


                            if (g.drawImage(buff, 0, 0, getWidth(), getHeight() -150, 0, 0, buff.getWidth(), buff.getHeight(), null))
                                if(runnable == false){
                                    File outputfile = new File("image.jpg");
                                    ImageIO.write(buff, "jpg", outputfile);
                                     String decodedText = QRCodeBean.readQrCode(outputfile);


                                     String FilePath = outputfile.getAbsolutePath();
                                      // Encode in JPEG


                                    if(outputfile.delete()){
                                             System.out.println(outputfile.getName() + " is deleted!");
                                            outputfile = null;
                                    }else{
                                             System.out.println("Delete operation is failed.");
                                            outputfile = null;
                                    }

                                     if(decodedText == null) {
                                        jTextArea1.setText("No QR Code found in the image");
                                     } else {
                                        jTextArea1.setText("Decoded text = " + decodedText);
                                     }
                                    System.out.println("Going to wait()");
                                    this.wait();
                                }
                            }else{
                                System.out.println("Highgui is unsuccessful"); 
                            }

                    } catch (IOException ex) {
                         System.out.println("Could not decode QR Code, IOException :: " + ex.getMessage());
                    } catch (InterruptedException ex) {
                        Logger.getLogger(QRForm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }


}

Can anyone help me?