保存捕获的图像时出现JavaCV错误 [英] JavaCV error when saving a captured image
问题描述
当我单击捕获"按钮时出现此错误.
This error comes up when I click my Capture button.
OpenCV错误:未指定的错误(无法找到 指定的扩展名)在cv :: imwrite_中,文件 C:\ build \ 2_4_winpack-bindings-win64-vc14-static \ opencv \ modules \ highgui \ src \ loadsave.cpp, 275行 线程"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: 错误:(-2)在以下位置找不到指定扩展名的编写器 函数cv :: imwrite_ ]
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);
}
推荐答案
使用imwrite
编写图像时,必须指定扩展名,只需执行以下操作:
When you write an image using imwrite
you must specify the extension, just do something like this:
Highgui.imwrite(file.getPath()+"\\image.jpg", frame);
.jpg 是扩展名.
这篇关于保存捕获的图像时出现JavaCV错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!