如何利用OpenCV帧差法识别显著差异的图像帧?

2026-04-29 07:472阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计607个文字,预计阅读时间需要3分钟。

如何利用OpenCV帧差法识别显著差异的图像帧?

本文以实例展示了如何使用OpenCV的差分法找出差异较大的图像。以下为具体步骤和内容概述:

1. 实例背景:某大家分享了一个使用OpenCV进行图像差异检测的实例,目的是找出图像中差异较大的部分。

2. 方法概述: - 使用OpenCV库进行图像处理。 - 通过计算图像的灰度差分,找出差异较大的区域。

3. 具体步骤: - 读取两幅图像。 - 将图像转换为灰度图。 - 计算两幅图像的灰度差分。 - 对差分图像进行阈值处理,提取差异较大的区域。 - 可视化处理结果。

4. 参考内容: - OpenCV库的基本使用方法。 - 图像灰度化、差分计算、阈值处理等操作。 - 图像处理结果的可视化展示。

如何利用OpenCV帧差法识别显著差异的图像帧?

5. 总结: - 通过实例展示了如何使用OpenCV的差分法找出图像中差异较大的部分。 - 为读者提供了实用的图像处理技巧和参考内容。

本文实例为大家分享了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); } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。

本文共计607个文字,预计阅读时间需要3分钟。

如何利用OpenCV帧差法识别显著差异的图像帧?

本文以实例展示了如何使用OpenCV的差分法找出差异较大的图像。以下为具体步骤和内容概述:

1. 实例背景:某大家分享了一个使用OpenCV进行图像差异检测的实例,目的是找出图像中差异较大的部分。

2. 方法概述: - 使用OpenCV库进行图像处理。 - 通过计算图像的灰度差分,找出差异较大的区域。

3. 具体步骤: - 读取两幅图像。 - 将图像转换为灰度图。 - 计算两幅图像的灰度差分。 - 对差分图像进行阈值处理,提取差异较大的区域。 - 可视化处理结果。

4. 参考内容: - OpenCV库的基本使用方法。 - 图像灰度化、差分计算、阈值处理等操作。 - 图像处理结果的可视化展示。

如何利用OpenCV帧差法识别显著差异的图像帧?

5. 总结: - 通过实例展示了如何使用OpenCV的差分法找出图像中差异较大的部分。 - 为读者提供了实用的图像处理技巧和参考内容。

本文实例为大家分享了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); } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。