如何使用OpenCV查找帧之间的差异? [英] How to find the differences between frames using OpenCV?

查看:431
本文介绍了如何使用OpenCV查找帧之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenCV上运行视频时,如何找到帧之间的差异?我需要做一个循环,检查逐帧的变化并在另一个窗口中显示结果吗? 我可以在这里附加的循环中执行此操作吗?还是有另一种方法可以做到?

How can I find the differences between frames when I'm running video on OpenCV? I need to do a loop that checks the changes from frame to frame and displays the result in another window? Can I do it in the loop that i attach here? Or is there another way to do it?

while( key != 'x' )  
{  
   frame = cvQueryFrame( capture );
   cvCvtColor(frame, gray, CV_RGB2GRAY);

   //gray_frame = cvQueryFrame( capture );

   //cvCvtColor(frame, gray_frame, CV_BGR2GRAY);

   if(key==27)
        break;

   cvShowImage( "video",frame );
   cvShowImage( "grayvideo",gray );

   key = cvWaitKey( 1000 / fps );  
}  
cvDestroyWindow( "video" );  
cvDestroyWindow( "grayvideo" ); 
cvReleaseCapture( &capture );  

return 0;


我在命令窗口中收到此错误:编译器未对齐堆栈变量. Libavcodec编译错误 可能会非常慢或崩溃.这不是libavcodec中的错误, 但在编译器中.您可以尝试使用gcc> = 4.2重新编译. 不要向FFmpeg开发人员报告崩溃. OpenCV错误:断言失败(src1.size()== dst.size()&& src1.type()== dst. type())在未知函数中,文件........ \ ocv \ opencv \ src \ cxcore \ cxarithm.cpp ,第1563行


i get this error on the command window:Compiler did not align stack variables. Libavcodec has been miscompiled and may be very slow or crash. This is not a bug in libavcodec, but in the compiler. You may try recompiling using gcc >= 4.2. Do not report crashes to FFmpeg developers. OpenCV Error: Assertion failed (src1.size() == dst.size() && src1.type() == dst. type()) in unknown function, file ........\ocv\opencv\src\cxcore\cxarithm.cpp , line 1563

深度的大小的玛比错了吗? 我该如何解决?还是maby代码有问题? 非常感谢您的帮助

what is wrong maby the maby the size of depth? how can i fix it? or maby something wrong with the code? thanks a lot for your help

推荐答案

您可以减去两个Mat对象/指针.

You can subtract the two Mat objects/pointers.

Mat prev_frame;
cap.read(prev_frame);

while (1)
{
    Mat frame;
    cap.read(frame);

    Mat dif = frame - prev_frame;
    imshow("difference", dif);

    // you can also use absdiff
    //absdiff(frame, prev_frame, dif);

    prev_frame = frame.clone();
}

这篇关于如何使用OpenCV查找帧之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆