opencv 帧差法找出相差大的图像(包含访问mat的像素值)

#include "stdafx.h"
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define IMAGENO 18456
using namespace std;
using namespace cv;

int main(int argc,char * argv())
{
	string ImgName;
	char OutName[100];
	Mat Image,tempImage,previousImage,currentImage,resultImage;

	ifstream fin("ImageList.txt");
	//ifstream fin("new.txt");

	for(int num=0; num 0)
		{
			cvtColor(tempImage, currentImage, CV_BGR2GRAY);
			absdiff(currentImage,previousImage,resultImage);  //帧差法,相减
			threshold(resultImage, resultImage, 20, 255.0, CV_THRESH_BINARY); //二值化,像素值相差大于20则置为255,其余为0
			int counter = 0;
			// 访问mat中的像素
			for (int i=0; i(i); //获取每一行的指针
				for (int j=0;j 4000) //达到阈值的像素数达到一定的数量则保存该图像
			{
				sprintf(OutName,"E:\\Image筛选之后\\%5d.jpg",num);
				imwrite(OutName,Image);
			}
			cvtColor(tempImage, previousImage, CV_BGR2GRAY); 
		}		
	}
}

你可能感兴趣的:(C,+,OpenCV)