如何通过相机集成设备获得足部压力印象 [英] How to get Foot pressure impression by a camera integrated device
问题描述
我想制作一个足部压力测量软件,我正在使用一个集成了摄像头并显示足部印象的设备。
直到现在我正在使用Aforge.net dll从设备捕获图像并将该图像转换为灰度,然后在每个像素上找到颜色,并在图像中找到根据深灰色设置的颜色。
但是我做了以下代码并不是我的工作,它是一个正确的方法来处理它吗?
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)
{
//selected video source
FinalVideoSource = new VideoCaptureDevice(VideoCaptureDevices[cmb_cameras.SelectedIndex].MonikerString);
FinalVideoSource.NewFrame += new NewFrameEventHandler(FinalVideoSource_NewFrame);
FinalVideoSource.Start();
}
void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
//System.Console.WriteLine("1: Flag status: " + flag.ToString());
if (flag!=true)
{
flag = true;
//System.Console.WriteLine("2: Flag status: "+ flag.ToString());
lock (NewBitmap)
{
using (ImageAttributes attributes = new ImageAttributes())
{
LiveImage = (Bitmap)eventArgs.Frame.Clone();
Graphics g = Graphics.FromImage(NewBitmap);
//create the grayscale ColorMatrix
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);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(LiveImage, new Rectangle(0, 0, 640, 480),
0, 0, 640, 480, GraphicsUnit.Pixel, attributes);
//--------------------------- Method 2ND ----------------------------------
// System.Diagnostics.Stopwatch sWatch = new System.Diagnostics.Stopwatch();
// sWatch.Start();
// PB_LiveImage.Image = LiveImage;
PB_LiveImage.Image = ChangeColor();
//sWatch.Stop();
//MessageBox.Show(sWatch.ElapsedMilliseconds.ToString());
}
}
}
}
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++)
{
//Console.WriteLine((System.Drawing.Color.LightGray.ToArgb() == lockBitmap.GetPixel(x, y).ToArgb()) + " LightGray");
//Console.WriteLine((System.Drawing.Color.Gray.ToArgb() == lockBitmap.GetPixel(x, y).ToArgb()) + " Gray");
//Console.WriteLine((System.Drawing.Color.DarkGray.ToArgb() == lockBitmap.GetPixel(x, y).ToArgb()) + " DarkGray");
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;
}
推荐答案
整个想法是调用 System.Drawing.Bitmap.LockBits
并使用 System.Drawing.Imaging.BitmapData
从此调用返回以直接操作锁定的图像内存。查看代码示例以了解如何执行此操作:
http:// msdn.microsoft.com/en-us/library/5ey6h79d.aspx [ ^ ]。
在您的代码示例中,您对 LockBits的调用
完全没有意义。你没有对你的位图做任何事情。当您按照上面引用的代码示例中显示的方式实际执行此操作时,它将解决您的所有问题。
至于 GetPixel / SePixel
,不仅这些调用完全违背了 LockBits
的目的,它们也非常慢,只有在你想要阅读或修改的情况下才能使用它们像素,以非常简单的方式。
The whole idea is to call System.Drawing.Bitmap.LockBits
and use System.Drawing.Imaging.BitmapData
returned from this call to directly manipulate locked image memory. Look at the code sample to see how to do it:
http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^].
In your code sample, your call to LockBits
is totally pointless. You don''t do anything to your bitmap. When you actually do it in the way shown in the code sample referenced above, it will solve all your problem.
As to GetPixel/SePixel
, not only these calls totally defeat the purpose of LockBits
, they also prohibitively slow and should only be used if you want to read or modify very few pixels, in a very simplified way.
这篇关于如何通过相机集成设备获得足部压力印象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!