gpt4 book ai didi

c++ - 图像差异 : How to find minor differences between images?

转载 作者:行者123 更新时间:2023-11-30 04:18:46 27 4
gpt4 key购买 nike

出于安全目的,我想找到 hwo 来获取差异黑白 2 相似的灰度图像,以便在系统中实现。我想检查它们之间是否发生了任何差异。对于对象跟踪,我在下面的程序中实现了精明的检测。我很容易得到结构化对象的轮廓……稍后减去 cn 以仅给出增量图像差异的轮廓……但是如果第二张图像中存在非结构性差异(例如烟或火)怎么办?我增加了对比度以进行更清晰的边缘检测,并修改了 canny fn 参数中的阈值。但没有得到合适的结果。

canny edge 也检测阴影边缘。如果我的两张相似图像是在一天中的不同时间拍摄的,则阴影会有所不同,因此边缘也会有所不同,并会产生不良的误报

我应该如何解决这个问题?谁能帮忙?谢谢!在enter code hereopencv 2.4 in visual studio 2010

中使用c语言api
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include <math.h>
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
IplImage* img1 = NULL;
if ((img1 = cvLoadImage("libertyH1.jpg"))== 0)
{
printf("cvLoadImage failed\n");
}
IplImage* gray1 = cvCreateImage(cvGetSize(img1), IPL_DEPTH_8U, 1); //contains greyscale //image
CvMemStorage* storage1 = cvCreateMemStorage(0); //struct for storage
cvCvtColor(img1, gray1, CV_BGR2GRAY); //convert to greyscale
cvSmooth(gray1, gray1, CV_GAUSSIAN, 7, 7); // This is done so as to //prevent a lot of false circles from being detected
IplImage* canny1 = cvCreateImage(cvGetSize(gray1),IPL_DEPTH_8U,1);
IplImage* rgbcanny1 = cvCreateImage(cvGetSize(gray1),IPL_DEPTH_8U,3);
cvCanny(gray1, canny1, 50, 100, 3); //cvCanny( const //CvArr* image, CvArr* edges(output edge map), double threshold1, double threshold2, int //aperture_size CV_DEFAULT(3) );

cvNamedWindow("Canny before hough");
cvShowImage("Canny before hough", canny1);
CvSeq* circles1 = cvHoughCircles(gray1, storage1, CV_HOUGH_GRADIENT, 1, gray1->height/3, 250, 100);
cvCvtColor(canny1, rgbcanny1, CV_GRAY2BGR);
cvNamedWindow("Canny after hough");
cvShowImage("Canny after hough", rgbcanny1);
for (size_t i = 0; i < circles1->total; i++)
{
// round the floats to an int
float* p = (float*)cvGetSeqElem(circles1, i);
cv::Point center(cvRound(p[0]), cvRound(p[1]));
int radius = cvRound(p[2]);
// draw the circle center
cvCircle(rgbcanny1, center, 3, CV_RGB(0,255,0), -1, 8, 0 );
// draw the circle outline
cvCircle(rgbcanny1, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );

printf("x: %d y: %d r: %d\n",center.x,center.y, radius);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////

IplImage* img2 = NULL;
if ((img2 = cvLoadImage("liberty_wth_obj.jpg"))== 0)
{
printf("cvLoadImage failed\n");
}
IplImage* gray2 = cvCreateImage(cvGetSize(img2), IPL_DEPTH_8U, 1);
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor(img2, gray2, CV_BGR2GRAY);
// This is done so as to prevent a lot of false circles from being detected
cvSmooth(gray2, gray2, CV_GAUSSIAN, 7, 7);
IplImage* canny2 = cvCreateImage(cvGetSize(img2),IPL_DEPTH_8U,1);
IplImage* rgbcanny2 = cvCreateImage(cvGetSize(img2),IPL_DEPTH_8U,3);
cvCanny(gray2, canny2, 50, 100, 3);
CvSeq* circles2 = cvHoughCircles(gray2, storage, CV_HOUGH_GRADIENT, 1, gray2->height/3, 250, 100);
cvCvtColor(canny2, rgbcanny2, CV_GRAY2BGR);
for (size_t i = 0; i < circles2->total; i++)
{
// round the floats to an int
float* p = (float*)cvGetSeqElem(circles2, i);
cv::Point center(cvRound(p[0]), cvRound(p[1]));
int radius = cvRound(p[2]);
// draw the circle center
cvCircle(rgbcanny2, center, 3, CV_RGB(0,255,0), -1, 8, 0 );
// draw the circle outline
cvCircle(rgbcanny2, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );
printf("x: %d y: %d r: %d\n",center.x,center.y, radius);
}

最佳答案

你需要这里的代码帮助吗?这不是一件容易的事。互联网上可用的算法很少,或者您可以尝试发明一种新算法。很多研究都在这方面进行。我对一个过程有一些想法。您可以通过 YCbCr 颜色系统中的 Y 找到边缘。从模糊图像的 Y 值中减去此 Y 值。那么你将获得优势。现在做一个数组表示。您必须将图像分成 block 。现在用 block 检查 block 。它可能会滑动、旋转、扭曲等。与阵列匹配进行比较。由于背景,对象跟踪很困难。小心/小心省略不必要的对象。

关于c++ - 图像差异 : How to find minor differences between images?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16235158/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com