帧差法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25//取两帧图像 if(preSafetyRopeDetectionFrame.empty()){ preSafetyRopeDetectionFrame = curFrame;//将第一帧赋给preFrame preSafetyRopeDetectionFrameIdx = detectTrackInfo.GetCurFrameIdx(); } else{ if((detectTrackInfo.GetCurFrameIdx() - preSafetyRopeDetectionFrameIdx) % 10 == 0){ SafetyRopeDetection(curFrame, dressingCheckResultVec, eventOccur);//安全绳的检测实现 preSafetyRopeDetectionFrame = curFrame; preSafetyRopeDetectionFrameIdx = detectTrackInfo.GetCurFrameIdx(); } } //帧差法--未进行形态学处理(膨胀,边缘等操作) cv::Mat frameROI = curFrame(detectSafetyRopeROI); //取检测区域ROI cv::Mat showImg = frameROI.clone(); cv::Mat preFrameROI = preSafetyRopeDetectionFrame(detectSafetyRopeROI); cvtColor(frameROI, frameROI, cv::COLOR_BGR2GRAY); //转成灰度图 cvtColor(preFrameROI, preFrameROI, cv::COLOR_BGR2GRAY); //转成灰度图 cv::Mat cutframe; absdiff(frameROI, preFrameROI, cutframe); //图像做差 cv::imwrite("cha.jpg", cutframe); cv::threshold(cutframe, cutframe, 100, 255, cv::THRESH_BINARY); //二值化差值图像 cv::imwrite("2.jpg", cutframe);
三帧差法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35//取三帧图像 if(preSafetyRopeDetectionFrame.empty()){ preSafetyRopeDetectionFrame = curFrame;//将第一帧赋给preFrame preSafetyRopeDetectionFrameIdx = detectTrackInfo.GetCurFrameIdx(); } else if(midSafetyRopeDetectionFrame.empty() && (detectTrackInfo.GetCurFrameIdx()- preSafetyRopeDetectionFrameIdx) % 20 == 0){ midSafetyRopeDetectionFrame = curFrame;//将第一帧赋给preFrame midSafetyRopeDetectionFrameIdx = detectTrackInfo.GetCurFrameIdx(); } else{ if((midSafetyRopeDetectionFrameIdx - preSafetyRopeDetectionFrameIdx) % 20 == 0 && (detectTrackInfo.GetCurFrameIdx() - midSafetyRopeDetectionFrameIdx) % 20 == 0){ SafetyRopeDetection(curFrame, dressingCheckResultVec, eventOccur);//安全绳的检测实现 preSafetyRopeDetectionFrame = midSafetyRopeDetectionFrame; preSafetyRopeDetectionFrameIdx = midSafetyRopeDetectionFrameIdx; midSafetyRopeDetectionFrame = curFrame; midSafetyRopeDetectionFrameIdx = detectTrackInfo.GetCurFrameIdx(); } } //三帧差法 cv::Mat preFrameROI = preSafetyRopeDetectionFrame(detectSafetyRopeROI); //取检测挂线的ROI区域 cv::Mat midFrameROI = midSafetyRopeDetectionFrame(detectSafetyRopeROI); cv::Mat frameROI = curFrame(detectSafetyRopeROI); cv::Mat showImg = midFrameROI.clone(); //保留第二帧原图用于画线 cvtColor(preFrameROI, preFrameROI, cv::COLOR_BGR2GRAY); //转成灰度图 cvtColor(midFrameROI, midFrameROI, cv::COLOR_BGR2GRAY); //转成灰度图 cvtColor(frameROI, frameROI, cv::COLOR_BGR2GRAY); //转成灰度图 cv::Mat difframe1,difframe2,difframe3,cutframe; absdiff(midFrameROI, preFrameROI, difframe1);//做差求绝对值 2-1 absdiff(midFrameROI, frameROI, difframe2);//做差求绝对值 2-3 bitwise_and(difframe1, difframe2, difframe3); //做与运算 cv::imwrite("cha.jpg", difframe3); cv::threshold(difframe3, cutframe, 100, 255, cv::THRESH_BINARY); //二值化差值图像 cv::imwrite("2.jpg", cutframe);
最后
以上就是称心绿草最近收集整理的关于帧差法和三帧差法的全部内容,更多相关帧差法和三帧差法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复