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

asked 2018-10-29 23:25:53 -0500

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?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by SULEIMMU
close date 2018-10-30 06:11:42.472080

Comments

please do not use outdated 2.4.6

are you aware, that the last frame of a video file will be empty ? (no, you can't simply try to retrieve() it again)

berak gravatar imageberak ( 2018-10-30 02:25:00 -0500 )edit

I am sorry. I am just newbie in Java ))... Where I empty last frame?

SULEIMMU gravatar imageSULEIMMU ( 2018-10-30 03:05:58 -0500 )edit

you simply have to stop, if grab() or retrieve() return false, the movie is over !

(you can also check frame.empty())

berak gravatar imageberak ( 2018-10-30 03:08:48 -0500 )edit

I think you didn't understood me. I am running VideoCapture in While(). It makes one iteration and give me an Exception. Then I re-run it and it works.

SULEIMMU gravatar imageSULEIMMU ( 2018-10-30 03:59:42 -0500 )edit

i can only comment, on what i see here.

you have to check, if the capture opened and also if grab & retrieve returned true.

there might also be a problem with multithreading there.

berak gravatar imageberak ( 2018-10-30 04:09:58 -0500 )edit

Ok thanks. Solved by adding version of OpenCv 3.2.0 But on executing camera there are an VideoCapture.retrieve_1(Native Method) error.

SULEIMMU gravatar imageSULEIMMU ( 2018-10-30 05:24:21 -0500 )edit

3.2.0 is still stone age.

and we can't help you, unless you show us the exact code you use and give us the exact errormsg

berak gravatar imageberak ( 2018-10-30 05:34:57 -0500 )edit