单击我的拍摄按钮时会出现此错误。保存拍摄图像时出现JavaCV错误
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_ ]
这是我的捕获按钮的代码。
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);
}
代码中的逻辑是什么?在第一次启动VideoCapture后,您立即释放它?并且在Highgui.imwrite(file.getPath(),frame)行中;'你在哪里以及如何捕获了框架?等等问题...... –
// btnPause Action事件 (myThread.runnable = FALSE; btnOpen.setEnabled(假); btnCapture.setEnabled(真); webSource.release();) –
// btnOpen行动event {webSource = new VideoCapture(0); myThread = new DaemonThread();线程t =新线程(myThread); t.setDaemon(true); myThread.runnable = true; t.start(); btnCapture.setEnabled(false); btnOpen.setEnabled(true); } –