[RESOLVED] Find the difference in two images.
If there's a built in function in the .NET framework for this, that would be really cool, however, I don't count on that happening, so I've been thinking about how to do such a thing.
I think that if I can figure out how to get and/or change the color value (in any format at all) of a specified pixel of a specified picture, I would be able to do it myself. For example if there is a function like GetPixel("C:\image.jpg", 30, 87) that might return a rgb value, or the color value as a long
If anyone has any help it would be greatly appreciated. Thanks in advanced!
Re: Find the difference in two images.
no builtin function obviously:D
The bitmap class has setpixel and getpixel methods. so if you have an Image object, you could do:
Bitmap bmp = (Bitmap) Image;
then bmp.SetPixel(...
SetPixel and GetPixel are slow though, so keep that in mind. You could access the pixels using unsafe code and pointers also. If you are interested in doing that (much harder, especially if you dont know what you're doing), look up Bitmap.LockBits...
Re: Find the difference in two images.
Bear in mind that you will have to load a JPG, because of the compression, but a bitmap file you could edit directly.
Re: Find the difference in two images.
Quote:
Originally Posted by penagate
Bear in mind that you will have to load a JPG, because of the compression, but a bitmap file you could edit directly.
For the time being, I'm pre-loading every image into a picturebox. So far it's working great. However, I'm a little worried about how this will perform as far as speed goes.
My final intention is to make a program that will detect motion from a webcam feed. I'll do this to detect change in any two chronological pictures. I still have to learn how to grab a pic from the webcam, but that's a whole different topic to be discussed later.
Re: Find the difference in two images.
If you want to detect movement like that you don't even need to check every pixel, just check every 5th or 10th pixel on both axes.
The way I did it was to have a class level array that would hold the colors of the sample points. Then compare them and replace them with the new values each time. This way you don't have to keep the previous image in memory.
You could just create it using the GetPixel SetPixel functions and replace that with unsafe code later, when you feel up to it.
Re: Find the difference in two images.
Quote:
Originally Posted by grilkip
If you want to detect movement like that you don't even need to check every pixel, just check every 5th or 10th pixel on both axes.
The way I did it was to have a class level array that would hold the colors of the sample points. Then compare them and replace them with the new values each time. This way you don't have to keep the previous image in memory.
You could just create it using the GetPixel SetPixel functions and replace that with unsafe code later, when you feel up to it.
I had the array idea in mind for sure.