Last post Oct 06, 2008 05:39 PM by iver56
Oct 05, 2008 07:40 AM|iver56|LINK
I've got a webcam which sends a picture (640x480, jpg) to the webserver once a minute. When somebody looks at the webcam page online, there should be a piece of code that finds the average color or brightness of the image (to find out if it is morning/day/evening
or night). Based on that, some other code will archive the image or not.
My question is: How can I find the average color of the webcam image?
Thanks in advance!
Oct 05, 2008 11:09 AM|SGWellens|LINK
Something like this?
Bitmap MyBitmap = new Bitmap(MapPath(@"~\Images\April.jpg"));
Rectangle Rect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
BitmapData BmpData = MyBitmap.LockBits(Rect,
int Size = BmpData.Stride * MyBitmap.Height;
byte RGBs = new byte[Size];
IntPtr Pointer = BmpData.Scan0;
System.Runtime.InteropServices.Marshal.Copy(Pointer, RGBs, 0, Size);
// we've got all the RGB values in an array
int Sum = 0;
for (int Index = 0; Index < RGBs.Length; Index++)
Sum += RGBs[Index];
// higher Average means a lighter picture (255 = white, 0 = black)
int Average = Sum / RGBs.Length;
Oct 06, 2008 05:39 PM|iver56|LINK
Thanks a lot!
It's just what I was looking for.