11 帧差法获取运动
Posted kekeoutlook
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了11 帧差法获取运动相关的知识,希望对你有一定的参考价值。
帧差法
三帧差法
录频工具转gif
#include "core/core.hpp" #include "highgui/highgui.hpp" #include "imgproc/imgproc.hpp" using namespace cv; int main(int argc, char *argv[]) { VideoCapture videoCap(0); if (!videoCap.isOpened()) { return -1; } double videoFPS = videoCap.get(CV_CAP_PROP_FPS); //获取帧率 double videoPause = 1000 / videoFPS; Mat framePrePre; //上上一帧 Mat framePre; //上一帧 Mat frameNow; //当前帧 Mat frameDet; //运动物体 videoCap >> framePrePre; videoCap >> framePre; cvtColor(framePrePre, framePrePre, CV_RGB2GRAY); cvtColor(framePre, framePre, CV_RGB2GRAY); int save = 0; while (true) { videoCap >> frameNow; // if (frameNow.empty() || waitKey() == 27) if (frameNow.empty() ) { break; } cvtColor(frameNow, frameNow, CV_RGB2GRAY); Mat Det1; Mat Det2; absdiff(framePrePre, framePre, Det1); //帧差1 absdiff(framePre, frameNow, Det2); //帧差2 threshold(Det1, Det1, 0, 255, CV_THRESH_OTSU); //自适应阈值化 threshold(Det2, Det2, 0, 255, CV_THRESH_OTSU); Mat element = getStructuringElement(0, Size(3, 3)); //膨胀核 dilate(Det1, Det1, element); //膨胀 dilate(Det2, Det2, element); bitwise_and(Det1, Det2, frameDet); framePrePre = framePre; framePre = frameNow; imshow("Video", frameNow); imshow("Detection", frameDet); waitKey(1); } return 0; }
以上是关于11 帧差法获取运动的主要内容,如果未能解决你的问题,请参考以下文章
图像识别基于帧差法和颜色空间实现火灾检测matlab源码GUI