Dear someone:
Now I am trying to do some "object Tracing" by using my web-camera. I read some paper said that I need to catch one picture to be the background and use another picture to find out different part to circular it out.
But when I compiled my program, it said that GDI+ error....I don't know it's my logical part incorrect or what should I need to change.
private void timer2_Tick(object sender, EventArgs e)
{
Bitmap myBitmap1 = pictureBox1.Image as Bitmap;
if (myBitmap1 == null)
{
timer2.Stop();
}
else
{
int[, ,] ImgData1 = GetImgData(myBitmap1);
GrayProcess(ImgData1);
GrayThreshold(ImgData1);
Bitmap ProcessedBitmap1 = CreateBitmap(ImgData1);
ProcessedBitmap1.Save(@"c:\temp1.jpg");
delay(1);
int[, ,] ImgData2 = GetImgData(myBitmap1);
GrayProcess(ImgData2);
GrayThreshold(ImgData2);
Bitmap ProcessedBitmap2 = CreateBitmap(ImgData2);
ProcessedBitmap2.Save(@"c:\temp2.jpg");
}
Bitmap source1 = new Bitmap(@"c:\temp1.jpg");
Bitmap source2 = new Bitmap(@"c:\temp2.jpg");
int[, ,] New1 = new int[source1.Width, source1.Height, 3];
int[, ,] New2 = new int[source2.Width, source2.Height, 3];
BitmapData byteArray1 = source1.LockBits(new Rectangle(0, 0, source1.Width, source1.Height),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
BitmapData byteArray2 = source2.LockBits(new Rectangle(0, 0, source2.Width, source2.Height),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int ByteOfSkip1 = byteArray1.Stride - byteArray1.Width * 3;
int ByteOfSkip2 = byteArray2.Stride - byteArray2.Width * 3;
unsafe
{
byte* imgPtr1 = (byte*)(byteArray1.Scan0);
byte* imgPtr2 = (byte*)(byteArray2.Scan0);
for (int y = 0; y <byteArray1.Height; y++)
{
for (int x = 0; x < byteArray1.Width; x++)
{
New1[x, y, 2] = (int)*(imgPtr1);
New1[x, y, 1] = (int)*(imgPtr1+1);
New1[x, y, 0] = (int)*(imgPtr1+2);
New2[x, y, 2] = (int)*(imgPtr2);
New2[x, y, 1] = (int)*(imgPtr2 + 1);
New2[x, y, 0] = (int)*(imgPtr2 + 2);
imgPtr1 += 3;
imgPtr2 += 3;
int a = New1[x, y, 1];
int b = New2[x, y, 1];
if (a != b)
{
Graphics g = pictureBox1.CreateGraphics();
Pen pen = new Pen(Color.Red, 5);
int width, height,width1,height1;
width = source1.Width;
height = source1.Height;
width1 = pictureBox1.Size.Width;
height1 = pictureBox1.Size.Height;
int width_diff, height_diff;
width_diff = width1 - width;
height_diff = height1 - height;
g.DrawRectangle(pen, x, y, width_diff, height_diff);
}
}
imgPtr1 += ByteOfSkip;
imgPtr2 += ByteOfSkip;
}
}
source1.UnlockBits(byteArray1);
source2.UnlockBits(byteArray2);
}