cvReleaseCapture() error
cvReleaseCapture() error
本文关键字:error cvReleaseCapture 更新时间:2023-10-16
为了使我的问题更清楚,请查看以下代码:
对于捕捉图像:
void CameraTest ::on_snapButton_clicked()
{
CvCapture* capture = cvCaptureFromCAM(0); // capture from video device #0
cvSetCaptureProperty(capture ,CV_CAP_PROP_FRAME_WIDTH , 800);
cvSetCaptureProperty(capture ,CV_CAP_PROP_FRAME_HEIGHT , 600);
if(!cvGrabFrame(capture)) //if no webcam detected or failed to capture anything
{ // capture a frame
cout << "Could not grab a framen7";
exit(0);
}
IplImage* img=cvRetrieveFrame(capture); // retrieve the captured frame
cv::Mat imageContainer(img);
image=imageContainer;
cv::imshow("Mat",image);
//cvReleaseCapture(&capture); When I enable this, and run the programming calling this, there will be an error.
}
现在,程序显示图像:
void CameraTest ::on_processButton_clicked()
{
cv::imshow("image snapped", image);
//my image processing steps...
}
启用cvReleaseCapture(&capture)
行时,收到以下错误:
Unhandled exception at 0x00fc3ff5 in CameraTest.exe: 0xC0000005: Access violation reading location 0x042e1030.
当我评论/删除该行时,我能够在单击另一个按钮时正确显示图像,但是当我想捕捉新图像时,我必须单击该按钮几次,这是程序的主要缺陷。有没有办法绕过它?
- 避免过时的c-api(IplImages,Cv*functions)坚持使用C ++ API。
- 您从捕获点到凸轮驱动程序内部的内存获得的图像。 如果你不克隆()图像,并释放捕获,你会得到一个悬空的指针。
- 不要为每个镜头创建新捕获。(凸轮需要一些"预热"时间,所以它会很慢)。改为在类中保留一个实例
class CameraTest
{
VideoCapture capture; // make it a class - member
CameraTest () : capture(0) // capture from video device #0
{
capture.set(CV_CAP_PROP_FRAME_WIDTH , 800);
capture.set(CV_CAP_PROP_FRAME_HEIGHT , 600);
}
// ...
};
void CameraTest ::on_snapButton_clicked()
{
Mat img; // temp var pointing todriver mem
if(!capture.read(img)) //if no webcam detected or failed to capture anything
{
cout << "Could not grab a framen7";
exit(0);
}
image = img.clone(); // keep our member var alive
cv::imshow("Mat",image);
}
替换 :
if(!cvGrabFrame(capture)) //if no webcam detected or failed to capture anything
{ // capture a frame
cout << "Could not grab a framen7";
exit(0);
}
由
if ( !capture )
{
cout << "Could not grab a framen7";
exit(0);
}
并替换
IplImage* img=cvRetrieveFrame(capture);
由
IplImage* img = cvQueryFrame( capture );
cvQueryFrame 抓取并从视频或相机返回帧。此函数是一次调用中 cvGrabFrame 和 cvRetrieveFrame 的combination
。返回的镜像不应由用户发布或修改。
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 对象声明中的模板"error: expected expression"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- OpenCV 3.4.1 error readNetFromTensorflow 无法在 cv::d nn::ReadProtoFromBinaryFile 中打开 .pb
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 为什么我会"error: expected expression"?
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- 如果两个静态库使用相同的另一个静态库,如何避免"LNK2005 Already Defined error"?
- 在 Objective-C++ -> EXC_BAD_ACCESS Error 中使用"new"关键字