I want to make a software for Foot pressure measurement and I am using a Device in which a camera is integrated and that show the foot impression.
Till now I am using Aforge.net dll for capture image from device and convert that image into grayscale and after that find out color on every pixel and set color according to dark gray is found in image.
But It is not work I have done following code for it and is it a right direction to process it?
private void cmb_cameras_SelectedIndexChanged(object sender, EventArgs e)
{
FinalVideoSource = new VideoCaptureDevice(VideoCaptureDevices[cmb_cameras.SelectedIndex].MonikerString);
FinalVideoSource.NewFrame += new NewFrameEventHandler(FinalVideoSource_NewFrame);
FinalVideoSource.Start();
}
void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
if (flag!=true)
{
flag = true;
lock (NewBitmap)
{
using (ImageAttributes attributes = new ImageAttributes())
{
LiveImage = (Bitmap)eventArgs.Frame.Clone();
Graphics g = Graphics.FromImage(NewBitmap);
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
attributes.SetColorMatrix(colorMatrix);
g.DrawImage(LiveImage, new Rectangle(0, 0, 640, 480),
0, 0, 640, 480, GraphicsUnit.Pixel, attributes);
PB_LiveImage.Image = ChangeColor();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Message:\n\nKindly closed the application.\nOne unhandled exception has been occurred!!");
}
}
public unsafe Bitmap ChangeColor()
{
Bitmap bmp = new Bitmap(NewBitmap);
LockBitClass lockBitmap = new LockBitClass(bmp);
lockBitmap.LockBits();
Color compareClr = Color.FromArgb(75, 75, 75);
Color compareClr2 = Color.FromArgb(90, 90, 90);
Color compareClr3 = Color.FromArgb(105, 105, 105);
Color compareClr4 = Color.FromArgb(150, 150, 150);
for (int y = 0; y < lockBitmap.Height; y++)
{
for (int x = 0; x < lockBitmap.Width; x++)
{
if (System.Drawing.Color.LightGray.ToArgb() == lockBitmap.GetPixel(x, y).ToArgb())
lockBitmap.SetPixel(x, y, Color.Cyan);
else if (System.Drawing.Color.Gray.ToArgb() == lockBitmap.GetPixel(x, y).ToArgb())
lockBitmap.SetPixel(x, y, Color.Yellow);
else if (System.Drawing.Color.DarkGray.ToArgb() == lockBitmap.GetPixel(x, y).ToArgb())
lockBitmap.SetPixel(x, y, Color.Red);
else
lockBitmap.SetPixel(x, y, Color.Blue);
}
}
lockBitmap.UnlockBits();
return bmp;
}