opencv帧差异未处理的异常
opencv frame difference Unhandled exception
我正在尝试用下面的代码进行帧差异处理。当我运行它时,它只显示第一帧并崩溃。你能帮我看看为什么会这样吗
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
cv::Mat frameCurrent, framePrev;
cv::Mat frameAbsDiff=;
//prepare Mats
VideoCapture cap("e.mp4");
cap >> frameCurrent;
framePrev = cv::Mat::zeros(frameCurrent.size(), frameCurrent.type());
cvtColor(frameCurrent, frameCurrent, CV_BGR2GRAY);
frameCurrent.copyTo(framePrev);
while (1)
{
if (frameCurrent.empty()) {
std::cout << "Frame1Message->End of sequence" << std::endl;
break;
}
cv::absdiff(frameCurrent, framePrev, frameAbsDiff);
imshow("frameCurrent", frameCurrent);
imshow("frameAbsDiff", frameAbsDiff);
if (waitKey(90) == 27)
break;
frameCurrent.copyTo(framePrev);
cap >> frameCurrent;
}
}
OpenCV错误:输入参数的大小不匹配(操作既不是"array op array"(其中数组具有相同的大小和相同的通道数),也不是"array op scalar"或"scalar op array’"),位于cv::numeric_op,文件C:\builds\2_4_PackSlave-win64-vc12-shared\OpenCV\modules\core\src\anumeric.cpp,第1287行
看起来应该在最后一个cap >> frameCurrent;
之后添加cvtColor(frameCurrent, frameCurrent, CV_BGR2GRAY);
。由于使用CV_BGR2GRAY
使用的是单通道图像,因此需要连贯并在所有帧中保持使用,否则将尝试在3通道图像和单通道图像之间应用减法。
在第二帧中,将出现此问题:CCD_ 4是RGB(3通道),而CCD_。您可以调试并确保。要解决此问题:更改:
frameCurrent.copyTo(framePrev);
cap >> frameCurrent;
至
frameCurrent.copyTo(framePrev);
cap >> frameCurrent;
cvtColor(frameCurrent, frameCurrent, CV_BGR2GRAY);
根据您的建议,我将代码更改为以下代码,当我运行时,它不会显示差异的结果
imshow("frameAbsDiff",frameAbsDdiff);
只是黑屏
int main()
{
cv::Mat frameCurrent, framePrev;
cv::Mat frameAbsDiff;
//prepare Mats
VideoCapture cap("m.mp4");
cap >> frameCurrent;
cvtColor(frameCurrent, frameCurrent, CV_BGR2GRAY);
frameCurrent.copyTo(framePrev);
while (1)
{
if (frameCurrent.empty()) {
std::cout << "Frame1Message->End of sequence" << std::endl;
break;
}
cv::absdiff(frameCurrent, framePrev, frameAbsDiff);
imshow("frameCurrent", frameCurrent);
imshow("frameAbsDiff", frameAbsDiff);
if (waitKey(90) == 27)
break;
cap >> frameCurrent;
cvtColor(frameCurrent, frameCurrent, CV_BGR2GRAY);
frameCurrent.copyTo(framePrev);
}
}
相关文章:
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- 在信号处理程序中捕获C++未处理的异常并恢复应用程序
- 在C++程序中使用的迭代器中未处理的异常
- 在 ******.exe 中0x00000000772CA267 (ntdll.dll) 处未处理的异常:0xC0000
- 未处理的异常与 cudaMemcpy2D
- 处理未处理的异常更改C++
- for 循环中未处理的异常
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- 为什么此代码导致未处理的异常失败
- 在OpenCV_core310.dll中使用findContours函数时,OpenCV引发未处理的异常
- 0x0F50DF58:0xC0000005:访问冲突读取位置0x0047CA04时未处理的异常
- 使用 getline 时未处理的异常
- 错误 : 异常 : 引发未处理的异常: 读取访问冲突.0xDDDDDDDD临时温度
- 核心消息传递中未处理的异常.dll在程序关闭期间
- 在 Hello World.exe 中0x0F828F0E (ucrtbased.dll) 处未处理的异常: 0xC00
- 从向量中删除元素时未处理的异常
- C++ 程序中双链表的未处理异常
- 在 Myfile.exe 中0x00831D39时未处理的异常:0xC00000FD:堆栈溢出(参数:0x0000000
- CUDA 编程未处理的异常和堆栈溢出
- 在多线程c++ 11程序中,当异常未处理时会发生什么