资源简介
帧差法实现前景背景分离,来自于BGSLibrary,对于静态的背景效果很好!
代码片段和文件信息
#include
#include
using namespace std;
using namespace cv;
//our sensitivity value to be used in the absdiff() function
const static int SENSITIVITY_VALUE = 20;
//size of blur used to smooth the intensity image output from absdiff() function
const static int BLUR_SIZE = 10;
//we‘ll have just one object to search for
//and keep track of its position.
int theobject[2] = {00};
//bounding rectangle of the object we will use the center of this as its position.
Rect objectBoundingRectangle = Rect(0000);
//int to string helper function
string intToString(int number){
//this function has a number input and string output
std::stringstream ss;
ss << number;
return ss.str();
}
int main(){
//these two can be toggled by pressing ‘d‘ or ‘t‘
bool debugMode = true;
//pause and resume code
bool pause = false;
//set up the matrices that we will need
//the two frames we will be comparing
Mat frame1frame2;
//their grayscale images (needed for absdiff() function)
Mat grayImage1grayImage2;
//resulting difference image
Mat differenceImage;
//thresholded difference image (for use in findContours() function)
Mat thresholdImage;
//video capture object.
VideoCapture capture;
while(1){
//we can loop the video by re-opening the capture every time the video reaches its last frame
capture.open(“video.avi“);
if(!capture.isOpened()){
cout<<“ERROR ACQUIRING VIDEO FEED\n“;
getchar();
return -1;
}
//check if the video has reach its last frame.
//we add ‘-1‘ because we are reading two frames from the video at a time.
//if this is not included we get a memory error!
while(capture.get(CV_CAP_PROP_POS_frameS)ame_COUNT)-1){
//read first frame
capture.read(frame1);
//convert frame1 to gray scale for frame differencing
cv::cvtColor(frame1grayImage1COLOR_BGR2GRAY);
//copy second frame
capture.read(frame2);
//convert frame2 to gray scale for frame differencing
cv::cvtColor(frame2grayImage2COLOR_BGR2GRAY);
//perform frame differencing with the sequential images. This will output an “intensity image“
//do not confuse this with a threshold image we will need to perform thresholding afterwards.
cv::absdiff(grayImage1grayImage2differenceImage);
//threshold intensity image at a given sensitivity value
cv::threshold(differenceImagethresholdImageSENSITIVITY_VALUE255THRESH_BINARY);
if(debugMode==true){
//show the difference image and threshold image
cv::imshow(“Difference Image“differenceImage);
cv::imshow(“Threshold Image“ thresholdImage);
}else{
//if not in debug mode destroy the windows so we don‘t see them anymore
cv::destroyWindow(“Difference Image“);
cv::destroyWindow(“Threshold Image“);
}
//blur the image to get rid of the noise. This will output an intensity image
cv::blur(thresholdImagethresho
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-10-03 21:05 fr
目录 0 2014-10-03 20:57 fr
目录 0 2014-10-03 20:56 fr
文件 39845888 2014-10-03 21:05 fr
文件 921 2014-10-03 20:52 fr
文件 20480 2014-10-03 21:05 fr
目录 0 2014-10-03 20:57 fr
文件 762 2014-10-03 20:57 fr
文件 18994 2014-10-03 20:57 fr
文件 374 2014-10-03 20:57 fr
文件 2072 2014-10-03 20:57 fr
文件 93 2014-10-03 20:57 fr
文件 1252 2014-10-03 20:57 fr
文件 0 2014-10-03 20:57 fr
文件 363520 2014-10-03 20:57 fr
文件 561152 2014-10-03 20:57 fr
文件 4018 2014-10-03 20:54 fr
文件 942 2014-10-03 20:54 fr
文件 3967 2014-10-03 20:58 fr
文件 1049784 2012-02-02 09:30 fr
- 上一篇:带FATFS文件系统的SD卡读写SPI模式
- 下一篇:广和通GPRS模块G510
相关资源
- opencv分封装函数到dll
- opencv3.2 + contrib3.2完整编译
- vs2017+OpenCV3.43中值滤波函数使用例程
- opencv3.4.1 32位 Debug版本 x86VS2017编译
- 基于opencv的数字识别
- vc车牌识别程序源代码
- opencv1.1pre1版本
- 基于qt和opencv的图片变形程序
- 用opencv的SVM做行人识别
- opencv对头发图片进行颜色渲染源代码
- OpenCV基于霍夫变换实现对圆形物体的
- ippicv_2019_win_ia32_20180723_general.zip
- opencv 神经网络训练用英文字库.zip
- opencv金字塔模板匹配算法
- OpenCV级联分类器训练与使用教程与代
- VS2013+OpenCV3.4.1+OpenCVContrib(x64)编译好
- Vlc获取rtsp视频流opencv显示
- Opencv3.0.0人脸检测+识别代码,vs2012工
- ffmpeg4+OpenCV3+VS2017 H264编解码
- OpenCV与OpenGL实现增强现实
- 学习opencv 中文版 pdf 带完整目录
- ippicv_windows_20151201.zip
- 几个基于openCV开发的手势识别代码
- OpenCV3.3 mingw64位编译 包含contribute部分
- opencv3.2.0依赖项ippicv_linux_20151201.tgz
- Opencv3.2_VS2015_64bit_debug/release
- 多目标跟踪vs+opencv
- opencv 的汽车分类器的正样本。
- opencv人脸识别demo并保存头像小照片
- opencv 1.2 安装
评论
共有 条评论