JavaCV error when saving a captured image

♀尐吖头ヾ 提交于 2019-12-13 03:22:15

问题


This error comes up when I click my Capture button.

OpenCV Error: Unspecified error (could not find a writer for the specified extension) in cv::imwrite_, file C:\build\2_4_winpack-bindings-win64-vc14-static\opencv\modules\highgui\src\loadsave.cpp, line 275 Exception in thread "AWT-EventQueue-0" CvException [org.opencv.core.CvException: cv::Exception: C:\build\2_4_winpack-bindings-win64-vc14-static\opencv\modules\highgui\src\loadsave.cpp:275: error: (-2) could not find a writer for the specified extension in function cv::imwrite_ ]

This is the code for my Capture Button.

if (evt.getSource() == btnCapture) {
    webSource = new VideoCapture(0);
    myThread = new DaemonThread();
    Thread t = new Thread(myThread);
            t.setDaemon(true);
            myThread.runnable = true;
            t.start();

        }

myThread.runnable = false;
            webSource.release();



                    JFileChooser jFileChooser1 = new JFileChooser("./images");
                 int returnVal = jFileChooser1.showSaveDialog(this);

                if(returnVal == JFileChooser.APPROVE_OPTION){
                     File  file = jFileChooser1.getSelectedFile().getAbsoluteFile();
                     String path = jFileChooser1.getSelectedFile().getAbsolutePath();
                      f = new File(file.toURI());
                     Highgui.imwrite(file.getPath(), frame);
                }

                FileInputStream fis;
    try {
        fis = new FileInputStream(f);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                for(int readNum; (readNum = fis.read(buf)) != -1;){
                    bos.write(buf, 0, readNum);
    } 
 byte[] convict_image = bos.toByteArray();
    }catch (FileNotFoundException ex) {
        Logger.getLogger(cam.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(cam.class.getName()).log(Level.SEVERE, null, ex);
    }

回答1:


When you write an image using imwrite you must specify the extension, just do something like this:

Highgui.imwrite(file.getPath()+"\\image.jpg", frame);

Here the .jpg is the extension.



来源:https://stackoverflow.com/questions/46862120/javacv-error-when-saving-a-captured-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!