Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从摄影机查找帧差异时出错 intmain(intargc,char*argv[]) { 视频捕获上限(0); Mat-current_-frame; 垫上一层框架; Mat结果; 垫架; //上限开放(-1); 如果(!cap.isOpened()){ //当前帧; if(当前_frame.empty()) 打破 如果(!previous_frame.empty()){ //减去帧 减去(当前帧、上一帧、结果); } imshow(“窗口”,结果); 等候室(10); frame.copyTo(上一帧); } }_C++_Visual C++_Opencv_Image Processing_Computer Vision - Fatal编程技术网

C++ 从摄影机查找帧差异时出错 intmain(intargc,char*argv[]) { 视频捕获上限(0); Mat-current_-frame; 垫上一层框架; Mat结果; 垫架; //上限开放(-1); 如果(!cap.isOpened()){ //当前帧; if(当前_frame.empty()) 打破 如果(!previous_frame.empty()){ //减去帧 减去(当前帧、上一帧、结果); } imshow(“窗口”,结果); 等候室(10); frame.copyTo(上一帧); } }

C++ 从摄影机查找帧差异时出错 intmain(intargc,char*argv[]) { 视频捕获上限(0); Mat-current_-frame; 垫上一层框架; Mat结果; 垫架; //上限开放(-1); 如果(!cap.isOpened()){ //当前帧; if(当前_frame.empty()) 打破 如果(!previous_frame.empty()){ //减去帧 减去(当前帧、上一帧、结果); } imshow(“窗口”,结果); 等候室(10); frame.copyTo(上一帧); } },c++,visual-c++,opencv,image-processing,computer-vision,C++,Visual C++,Opencv,Image Processing,Computer Vision,当我运行这个程序从前一帧减去当前帧,然后显示结果帧时,它会在开始执行时显示这个错误 异常 我想在录制的视频上应用同样的方法我想问题出在previos\u frame上。您仅在循环的和处为上一帧指定值。 我认为它可能在while循环开始时是空的,所以 int main(int argc, char* argv[]) { VideoCapture cap(0); Mat current_frame; Mat previous_frame; Mat result;

当我运行这个程序从前一帧减去当前帧,然后显示结果帧时,它会在开始执行时显示这个错误

<0x575 D812F中未处理的异常:WC01.EXE:微软C++异常:CV::内存位置0x01FE848…< /P>异常
我想在录制的视频上应用同样的方法

我想问题出在
previos\u frame
上。您仅在循环的和处为上一帧指定值。 我认为它可能在while循环开始时是空的,所以

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); 
    }
}
块将不会执行

previous\u frame
在进行减法时也必须与
当前\u frame
的大小相同


此代码(减法)应确定要在下一行显示的
结果的大小。

在第1帧中,结果为空

if (! previous_frame.empty())  {
        // subtract frames
        subtract(current_frame, previous_frame, result);
    }
另外,您正在将空的
复制到
上一个\u帧
,它应该是
当前\u帧
,不是吗

试试看:

imshow("Window", result); // this will crash

你对框架做过什么?这可能不是您的错误,但看起来帧总是空的,所以您每次迭代都会将一个空帧复制到上一帧。@JoeRunde我想在视频上运行它,就像在任何录制的5分钟电影上一样,那么它怎么可能是空的呢?从第一帧到第二帧必须有一个变化?就像berak在他的回答中所说的,有一个叫做“帧”的垫子,你永远不会把任何东西放进去。您所做的是将下一帧放入“当前帧”,然后存储“结果”=“当前帧”-“上一帧”,然后存储“上一帧”=“帧”。看到问题了吗?你从来没有把任何东西放进“框架”@JoeRunde是的,我明白,你想说我不应该分配框架,因为它是emtpy
   if (! previous_frame.empty())  {
       // subtract frames
       subtract(current_frame, previous_frame, result);
       imshow("Window", result); 
   }
   waitKey(10);
   current_frame.copyTo(previous_frame); 
}