我正在尝试使用opencv的accumulateWeighted()函数,直到我遇到了这样的无法解决的问题。编译时没有报错,直到运行时才报错了。环境vs2022。opencv版本4.6.0。
#include
#include
using namespace cv;
int main()
{
Mat frame;
Mat before;
Mat proc;
Rect rect;
Mat gray;
Mat frameDelta;
Mat thresh;
Mat contours;
VideoCapture cap;
cap.open(0);
namedWindow("video");
cap.read(proc);
cvtColor(proc, before, COLOR_BGR2GRAY);
while (1) {
cap.read(proc);
cvtColor(proc, gray,COLOR_BGR2GRAY);
printf("%d,%d", gray.depth(), before.depth());
imshow("video", before);
waitKey(1);
accumulateWeighted(gray, before, 0.8);
convertScaleAbs(before,proc);
absdiff(gray, proc,frameDelta);
threshold(frameDelta, thresh, 3, 255, THRESH_BINARY);
findContours(thresh, contours,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);
for (int i = 0; i < proc.rows; i++)
{
rect = boundingRect(proc.rowRange(i,i));
printf("%d,%d", rect.x, rect.y);
}
imshow("video", proc);
waitKey(20);
}
return 0;
}
OpenCV(4.6.0) Error: Assertion failed (func != 0) in cv::accumulateWeighted, file c:\build\master_winpack-build-win64-vc15\opencv\modules\imgproc\src\accum.cpp, line 635
控制台调试显示两张图像深度值为0,即CV_8U。
imshow两张输入图像也是灰度的。
控制台窗口截图:
vs2022报错截图:
检索资料,发现:
但是打印出的和窗口显示出的图像均证明向accumulateWeighted()函数输入的两张图片是灰度图,并且深度是CV_8U,排除深度值问题。
行数和列数通过调试窗口发现均是相同的,排除行数和列数的问题。
控制台报错所指的文件的那几行,看不懂,附图:
不要再报错了,调试很久了都找不到问题很崩溃。
不知道你这个问题是否已经解决, 如果还没有解决的话: