EDN Admin
Well-known member
hello
I am doing a project that how to take a picture through webcam and convert it into bitmap after that to rgb , i have done up to here but ia m not getting how to avoid background noise and background can you please help me
this is the code wt i have wrote private void button4_Click(object sender, EventArgs e)
{
Byte bl, rd, gn;
Int32 Col, Row, Wdt, Hgt;
Color Pixel;
Rectangle r;
IntPtr Ptr;
Int32 Index;
OpenFileDialog Dlg = new OpenFileDialog();
BitmapData BmpData = new BitmapData();
if (true)
{
Wdt = bit.Width;
Hgt = bit.Height;
r = new Rectangle(0, 0, Wdt, Hgt);
bit.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb, BmpData);
Ptr = BmpData.Scan0;
int bytes = Math.Abs(BmpData.Stride) * bit.Height;
byte[] rgbValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(Ptr, rgbValues, 0, bytes);
for (Row = 0; Row < Hgt; Row++)
{
for (Col = 0; Col < Wdt * 3; Col = Col + 3)
{
Index = Row * Wdt * 3 + Col;
if (rgbValues[Index+1] < 25)
{
rgbValues[Index] = 12;
rgbValues[Index + 1] = 12;
rgbValues[Index + 2] = 12;
}
if (rgbValues[Index+1] < 50)
{
rgbValues[Index] = 25;
rgbValues[Index + 1] = 25;
rgbValues[Index + 2] = 25;
}
else if (rgbValues[Index+1] < 100)
{
rgbValues[Index] = 75;
rgbValues[Index + 1] = 75;
rgbValues[Index + 2] = 75;
}
else if (rgbValues[Index+1] < 125)
{
rgbValues[Index] = 100;
rgbValues[Index + 1] = 100;
rgbValues[Index + 2] = 100;
}
else if (rgbValues[Index+1] < 150)
{
rgbValues[Index] = 125;
rgbValues[Index + 1] = 125;
rgbValues[Index + 2] = 152;
}
else if (rgbValues[Index+1] < 175)
{
rgbValues[Index] = 150;
rgbValues[Index + 1] = 150;
rgbValues[Index + 2] = 150;
}
else if (rgbValues[Index+1] < 200)
{
rgbValues[Index] = 175;
rgbValues[Index + 1] = 175;
rgbValues[Index + 2] = 175;
}
else if (rgbValues[Index+1] < 225)
{
rgbValues[Index] = 200;
rgbValues[Index + 1] = 200;
rgbValues[Index + 2] = 200;
}
else if (rgbValues[Index+1] < 250)
{
rgbValues[Index] = 225;
rgbValues[Index + 1] = 225;
rgbValues[Index + 2] = 225;
}
else
{
rgbValues[Index+1] = 250;
rgbValues[Index + 1] = 250;
rgbValues[Index + 2] = 250;
}
}
}
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, Ptr, bytes);
bit.UnlockBits(BmpData);
pictureBox1.BackgroundImage = bit;
Dlg = null;
}
thanks and regards goutham sannidhi
View the full article
I am doing a project that how to take a picture through webcam and convert it into bitmap after that to rgb , i have done up to here but ia m not getting how to avoid background noise and background can you please help me
this is the code wt i have wrote private void button4_Click(object sender, EventArgs e)
{
Byte bl, rd, gn;
Int32 Col, Row, Wdt, Hgt;
Color Pixel;
Rectangle r;
IntPtr Ptr;
Int32 Index;
OpenFileDialog Dlg = new OpenFileDialog();
BitmapData BmpData = new BitmapData();
if (true)
{
Wdt = bit.Width;
Hgt = bit.Height;
r = new Rectangle(0, 0, Wdt, Hgt);
bit.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb, BmpData);
Ptr = BmpData.Scan0;
int bytes = Math.Abs(BmpData.Stride) * bit.Height;
byte[] rgbValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(Ptr, rgbValues, 0, bytes);
for (Row = 0; Row < Hgt; Row++)
{
for (Col = 0; Col < Wdt * 3; Col = Col + 3)
{
Index = Row * Wdt * 3 + Col;
if (rgbValues[Index+1] < 25)
{
rgbValues[Index] = 12;
rgbValues[Index + 1] = 12;
rgbValues[Index + 2] = 12;
}
if (rgbValues[Index+1] < 50)
{
rgbValues[Index] = 25;
rgbValues[Index + 1] = 25;
rgbValues[Index + 2] = 25;
}
else if (rgbValues[Index+1] < 100)
{
rgbValues[Index] = 75;
rgbValues[Index + 1] = 75;
rgbValues[Index + 2] = 75;
}
else if (rgbValues[Index+1] < 125)
{
rgbValues[Index] = 100;
rgbValues[Index + 1] = 100;
rgbValues[Index + 2] = 100;
}
else if (rgbValues[Index+1] < 150)
{
rgbValues[Index] = 125;
rgbValues[Index + 1] = 125;
rgbValues[Index + 2] = 152;
}
else if (rgbValues[Index+1] < 175)
{
rgbValues[Index] = 150;
rgbValues[Index + 1] = 150;
rgbValues[Index + 2] = 150;
}
else if (rgbValues[Index+1] < 200)
{
rgbValues[Index] = 175;
rgbValues[Index + 1] = 175;
rgbValues[Index + 2] = 175;
}
else if (rgbValues[Index+1] < 225)
{
rgbValues[Index] = 200;
rgbValues[Index + 1] = 200;
rgbValues[Index + 2] = 200;
}
else if (rgbValues[Index+1] < 250)
{
rgbValues[Index] = 225;
rgbValues[Index + 1] = 225;
rgbValues[Index + 2] = 225;
}
else
{
rgbValues[Index+1] = 250;
rgbValues[Index + 1] = 250;
rgbValues[Index + 2] = 250;
}
}
}
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, Ptr, bytes);
bit.UnlockBits(BmpData);
pictureBox1.BackgroundImage = bit;
Dlg = null;
}
thanks and regards goutham sannidhi
View the full article