概述
帧差法
//取两帧图像
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);
三帧差法
//取三帧图像
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);
最后
以上就是称心绿草为你收集整理的帧差法和三帧差法的全部内容,希望文章能够帮你解决帧差法和三帧差法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复