gpt4 book ai didi

image-processing - OPENCV怪异错误

转载 作者:行者123 更新时间:2023-12-02 17:54:57 25 4
gpt4 key购买 nike

我正在使用背景减法,并希望显示其内容。由于内存异常,代码似乎总是在某种程度上中断。该错误似乎是在cvCopy函数中。无法解决。

#include "cv.h"
#include "highgui.h"
#include "opencv2\core\operations.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\core\types_c.h"
#include "opencv\cxcore.h"
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int, char**)
{
bool flag=0;
VideoCapture cap(0); // open the default camera
VideoCapture cap1(0);
if(!cap.isOpened()) // check if we succeeded
return -1;

Mat gray,bg,result,frame,result1,final,frame1;
//CvMemStorage* contours = NULL;

cap>>frame;
cvtColor(frame,bg,CV_BGR2GRAY);

namedWindow("GRAY",1);

for(;;)
{
//final = Mat::zeros(mGreenScale.rows, mGreenScale.cols, CV_8UC3);
cap >> frame; // get a new frame from camera
cap1 >> frame1;
cvtColor(frame, gray, CV_BGR2GRAY);
absdiff(gray,bg,result);
threshold(result,result1,50,255,THRESH_BINARY);
//cvCopy(const CvArr* src, CvArr* dst, const CvArr* mask=NULL)¶
//cvCopy(&frame1, &final, &result1);
//findContours(result1,contours, ;CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
//drawContours(final,contours,-1,CV_RGB(0,255,0));
//imshow("GRAY",result1);
//imshow("GRAY", result);
imshow("GRAY1",final);

if(flag)
{
imshow("BG",bg);
}
//if(waitKey(0)==27) break;
if(waitKey(1)==32)
{
cvtColor(frame,bg,CV_BGR2GRAY);
flag=!flag;
}
if(waitKey(1)==27)
{
break;
}
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}

最佳答案

建议您不要使用C和C++ API,而应尽可能使用C++ API。如果只想复制矩阵,则只需使用Mat::clone()Mat::copyTo()即可。由于要使用掩码,因此可以使用copyTo成员函数,如下所示:

Mat final;
frame1.copyTo(final, result1);

希望有帮助!

关于image-processing - OPENCV怪异错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8717204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com