hi..

currently i have two image in my folder, how can i compare the two images for different based on the image pixel? or is there any other way which i could use to determined if the images are identical? (both images have the same size and resolution.) thus i need to scan each pixel of the image to determined the different.

how can i achieve that using C++?

???
ocw

U can open these picture file in binary mode and compare each charecter...

#include <iostream.h>
#include <fstream.h>

int main(void)
{
	char fileName1[50], fileName2[50];
	cout << "Enter files :\n";
	cin >> fileName1 >> fileName2;
	fstream filePtr1, filePtr2;
	filePtr1.open(fileName1,ios::in | ios::binary);
	filePtr2.open(fileName2,ios::in | ios::binary);
	filePtr1.seekg(0,ios::end);
	filePtr2.seekg(0,ios::end);
	if(filePtr1.tellg() != filePtr1.tellg())
	{
		cout << "Files are not identical..." << endl;
		return 0;
	}
	filePtr1.seekg(0,ios::beg);
	filePtr2.seekg(0,ios::beg);
	while(1)
	{
		int val1 = filePtr1.get();
		int val2 = filePtr2.get();
		if(val1 != val2)
		{
			cout << "Files are not identical..." << endl;
			return 0;
		}
		if(val1==EOF || val2==EOF) break;
	}
	cout << "Files are identical..." << endl;

	return 0;
}

hihi..

is comparing the imgae binary faster than comparing to the pixel of the image? my system processing usgae is quite high, therrefore, if the comparing module is lagging, my system may not be able to withstand it.

if i gotta compare the pixel of both images, how should i go about it? does hDC help?

should i do this-->

image1(hDC, x , y) --> send to array
image2(hDC, x, y) --> send to array


then i compare the the array of the pixel to check for the image different.

this is the logic i have, but i am lost in C++.

thanks..
ocw

U can open these picture file in binary mode and compare each charecter...

#include <iostream.h>
#include <fstream.h>

int main(void)
{
	char fileName1[50], fileName2[50];
	cout << "Enter files :\n";
	cin >> fileName1 >> fileName2;
	fstream filePtr1, filePtr2;
	filePtr1.open(fileName1,ios::in | ios::binary);
	filePtr2.open(fileName2,ios::in | ios::binary);
	filePtr1.seekg(0,ios::end);
	filePtr2.seekg(0,ios::end);
	if(filePtr1.tellg() != filePtr1.tellg())
	{
		cout << "Files are not identical..." << endl;
		return 0;
	}
	filePtr1.seekg(0,ios::beg);
	filePtr2.seekg(0,ios::beg);
	while(1)
	{
		int val1 = filePtr1.get();
		int val2 = filePtr2.get();
		if(val1 != val2)
		{
			cout << "Files are not identical..." << endl;
			return 0;
		}
		if(val1==EOF || val2==EOF) break;
	}
	cout << "Files are identical..." << endl;

	return 0;
}

hi amt_muk,

i have tried the code above but it did not actually compared the different between these 2 images. I am thinking of comparing the images by their individual pixel between each image. BUT, how am i going to go about it????

the attached images are the images i used to compare.

confuse...
ocw [;<

If you are interested in speed, then I think it is better to use the OpenCV library in sourceforges.net. http://sourceforge.net/projects/opencvlibrary/

There are a lot of built in image processing functions and they also provide good documentation. I have used some of it for image prcessing applications, and found them very fast. You can check the tutorials, especialy the one called http://prdownloads.sourceforge.net/opencvlibrary/ippocv.pdf to get started.

is there a "GetPixel" method in C++? but i need C++ to function my application.

how can i done that(Getpixel)?

???
ocw

There is one in the Windows GDI.

COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.