opencv帧差法找出相差大的图像
2020-03-22 12:07
776 查看
本文实例为大家分享了opencv帧差法找出相差大的图像,供大家参考,具体内容如下
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <iostream> #include <fstream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/objdetect/objdetect.hpp> #include <opencv2/ml/ml.hpp> #include <string.h> #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<IMAGENO && getline(fin,ImgName); num++) { cout <<"读入"<<ImgName<<endl; ImgName = "E:\\Image\\" + ImgName ; Image = imread(ImgName); resize(Image,tempImage,Size(130,130)); if (num == 0) { cvtColor(tempImage, previousImage, CV_BGR2GRAY); sprintf(OutName,"E:\\数据集\\目标区域图像\\StudentsArea抠图筛选\\%5d.jpg",num); imwrite(OutName,Image); } if (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<resultImage.rows; i++) { uchar *data = resultImage.ptr<uchar>(i); //获取每一行的指针 for (int j=0;j<resultImage.cols; j++) { if (data[j] == 255) //访问到像素值 { counter++; } } } if (counter > 4000) //达到阈值的像素数达到一定的数量则保存该图像 { sprintf(OutName,"E:\\Image筛选之后\\%5d.jpg",num); imwrite(OutName,Image); } cvtColor(tempImage, previousImage, CV_BGR2GRAY); } } }
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- opencv 帧差法找出相差大的图像(包含访问mat的像素值)
- 图像处理-找出三个苹果中最大的一个
- 找出图像中的全部联通域
- opencv找出两幅图像不同!
- 100亿个无序数,给定里面其中一个数A,找出与A大小相差最小的各10个数
- 孪生素数(找出数n范围内相差1或2的素数的个数)
- 数组A中任意两个相邻元素大小相差1,现给定这样的数组A和目标整数t,找出t在数组A中的位置。
- opencv找出图像最亮点并画圆
- (冒泡排序)找出数组中相差最小的两个元素
- 【面试题】-数组A中任意两个相邻元素大小相差1,找出某个数在数组A中的位置。(所有位置 )
- sqlite找出时间相差3天的记录
- 找出图像I的代数中心
- opencv 从原始的图像中找出ROI区域
- 光学显微镜自动聚焦之找出聚焦图像位置
- PET/CT图像的纹理特征提取
- Basler工业相机基于opencv 采集图像
- 解决ASP(图像)上传漏洞的方法
- Matlab学习20101207(图像读写和几何变换)
- 数字图像处理之二维码图像提取算法(一)【转】
- GAN在医学图像综述——Generative adversarial network in medical imaging: A review