从相机中查找帧的差异时出错
Error while finding differences in frames from camera
int main(int argc, char* argv[])
{
VideoCapture cap(0);
Mat current_frame;
Mat previous_frame;
Mat result;
Mat frame;
//cap.open(-1);
if (!cap.isOpened()) {
//cerr << "can not open camera or video file" << endl;
return -1;
}
while(1)
{
cap >> current_frame;
if (current_frame.empty())
break;
if (! previous_frame.empty()) {
// subtract frames
subtract(current_frame, previous_frame, result);
}
imshow("Window", result);
waitKey(10);
frame.copyTo(previous_frame);
}
}
当我运行这个程序从前一帧中减去当前帧,然后显示结果帧时,它在开始执行
时显示这个错误WK01.exe中0x755d812f的未处理异常:Microsoft c++ exception: cv:: exception at memory location 0x001fe848.
我想对录制的视频应用同样的东西
在第一帧中,结果为空!
imshow("Window", result); // this will crash
同样,你正在将空的frame
Mat复制到previous_frame
,那应该是current_frame
,不是吗?
试一试:
if (! previous_frame.empty()) {
// subtract frames
subtract(current_frame, previous_frame, result);
imshow("Window", result);
}
waitKey(10);
current_frame.copyTo(previous_frame);
}
我认为问题是与previos_frame
。只在循环结束时给previous_frame
赋值。我认为在while循环开始时它可能是空的,所以
if (! previous_frame.empty()) {
// subtract frames
subtract(current_frame, previous_frame, result);
}
块不会被执行。
previous_frame
也必须与current_frame
大小相同。
这段代码(减去方法)应该确定result
的大小,即您希望在下一行显示的内容。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 了解 GLM- openGL 中的相机转换
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- OpenGL相机和相机空间转型的困惑
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 如何在EDSDK中出错后重置相机
- 使用树莓派相机和打开简历显示视频时出错
- 从相机中查找帧的差异时出错