提取颜色Aforge.NET魔方
Extracting color Aforge.NET rubik's cube
我正在制作一个使用网络摄像头检测魔方面部的应用程序。我可以对斑点应用滤镜,但不知道如何获取每个斑点的颜色。
我到处找都没有找到。我使用 Visual Studio 2015 和 Aforge.NET
void Finalvideo_newframe(object sender, NewFrameEventArgs eventArgs)
{
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
Bitmap video2 = (Bitmap)eventArgs.Frame.Clone();
//Create color filter
HSLFiltering HslFilter = new HSLFiltering();
//configre the filter
HslFilter.Hue = new IntRange(minMat, maxMat);
HslFilter.Saturation = new Range(minSat, maxSat);
HslFilter.Luminance = new Range(minLum, maxLum);
//apply color filter to the image
HslFilter.ApplyInPlace(video2);
Grayscale grayFilter = Grayscale.CommonAlgorithms.BT709;
Bitmap grayImage = grayFilter.Apply(video2);
//display Image
BlobCounter blobcounter = new BlobCounter();
BlobsFiltering filtroTamaño = new BlobsFiltering();
//ConnectedComponentsLabeling filtroColor = new ConnectedComponentsLabeling();
CannyEdgeDetector filtroEsquinas = new CannyEdgeDetector();
BlobCounterBase bc = new BlobCounter();
blobcounter.FilterBlobs = true;
blobcounter.MinHeight = 30;
blobcounter.MinWidth = 30;
blobcounter.MaxHeight = 70;
blobcounter.MaxHeight = 70;
//filtroTamaño.MinHeight = 30;
//filtroTamaño.MinWidth = 30;
//filtroTamaño.MaxHeight = 70;
//filtroTamaño.MaxWidth = 70;
blobcounter.ObjectsOrder = ObjectsOrder.YX;
//locate blobs
//filtroTamaño.ApplyInPlace(grayImage);
blobcounter.ProcessImage(grayImage);
//filtroColor.Apply(grayImage);
//filtroEsquinas.ApplyInPlace(grayImage);
BitmapData objectsData = video.LockBits(new Rectangle(0, 0, video.Width, video.Height),
ImageLockMode.ReadOnly, video.PixelFormat);
video.UnlockBits(objectsData);
Rectangle[] rects = blobcounter.GetObjectsRectangles();
for (int i = 0; rects.Length > i; i++)
{
Rectangle objectRect1 = rects[i];
Graphics g = Graphics.FromImage(video);
//Graphics g = video.CreateGraphics()
using (Pen pen = new Pen(Color.Red, 3))
{
if (checkSeguimiento.Checked)
{
g.DrawRectangle(pen, objectRect1);
PointF drawPoin = new PointF(objectRect1.X, objectRect1.Y);
int objectX = objectRect1.X + objectRect1.Width / 2 - video.Width / 2;
int objectY = video.Height / 2 - (objectRect1.Y + objectRect1.Height / 2);
String Blobinformation = "X= " + objectX.ToString() + "\nY= " + objectY.ToString() + "\nSize=" + objectRect1.Size.ToString();
//g.DrawString(Blobinformation, new Font("Arial", 12), new SolidBrush(Color.Blue), drawPoin);
g.DrawString((i + 1).ToString(), new Font("Arial", 12), Brushes.Red, objectRect1);
}
}
g.Dispose();
}
pictureBox1.Image = video;
pictureBox2.Image = grayImage;
简单,在开始处理之前创建要处理的图像的位图(源)并创建副本(临时)进行处理,然后在处理时在 blob 矩形的中间获取一个点,然后使用这个
Color color = Source.GetPixel(x, y);
它将return您正在寻找的像素的颜色
我正在制作一个使用网络摄像头检测魔方面部的应用程序。我可以对斑点应用滤镜,但不知道如何获取每个斑点的颜色。
我到处找都没有找到。我使用 Visual Studio 2015 和 Aforge.NET
void Finalvideo_newframe(object sender, NewFrameEventArgs eventArgs)
{
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
Bitmap video2 = (Bitmap)eventArgs.Frame.Clone();
//Create color filter
HSLFiltering HslFilter = new HSLFiltering();
//configre the filter
HslFilter.Hue = new IntRange(minMat, maxMat);
HslFilter.Saturation = new Range(minSat, maxSat);
HslFilter.Luminance = new Range(minLum, maxLum);
//apply color filter to the image
HslFilter.ApplyInPlace(video2);
Grayscale grayFilter = Grayscale.CommonAlgorithms.BT709;
Bitmap grayImage = grayFilter.Apply(video2);
//display Image
BlobCounter blobcounter = new BlobCounter();
BlobsFiltering filtroTamaño = new BlobsFiltering();
//ConnectedComponentsLabeling filtroColor = new ConnectedComponentsLabeling();
CannyEdgeDetector filtroEsquinas = new CannyEdgeDetector();
BlobCounterBase bc = new BlobCounter();
blobcounter.FilterBlobs = true;
blobcounter.MinHeight = 30;
blobcounter.MinWidth = 30;
blobcounter.MaxHeight = 70;
blobcounter.MaxHeight = 70;
//filtroTamaño.MinHeight = 30;
//filtroTamaño.MinWidth = 30;
//filtroTamaño.MaxHeight = 70;
//filtroTamaño.MaxWidth = 70;
blobcounter.ObjectsOrder = ObjectsOrder.YX;
//locate blobs
//filtroTamaño.ApplyInPlace(grayImage);
blobcounter.ProcessImage(grayImage);
//filtroColor.Apply(grayImage);
//filtroEsquinas.ApplyInPlace(grayImage);
BitmapData objectsData = video.LockBits(new Rectangle(0, 0, video.Width, video.Height),
ImageLockMode.ReadOnly, video.PixelFormat);
video.UnlockBits(objectsData);
Rectangle[] rects = blobcounter.GetObjectsRectangles();
for (int i = 0; rects.Length > i; i++)
{
Rectangle objectRect1 = rects[i];
Graphics g = Graphics.FromImage(video);
//Graphics g = video.CreateGraphics()
using (Pen pen = new Pen(Color.Red, 3))
{
if (checkSeguimiento.Checked)
{
g.DrawRectangle(pen, objectRect1);
PointF drawPoin = new PointF(objectRect1.X, objectRect1.Y);
int objectX = objectRect1.X + objectRect1.Width / 2 - video.Width / 2;
int objectY = video.Height / 2 - (objectRect1.Y + objectRect1.Height / 2);
String Blobinformation = "X= " + objectX.ToString() + "\nY= " + objectY.ToString() + "\nSize=" + objectRect1.Size.ToString();
//g.DrawString(Blobinformation, new Font("Arial", 12), new SolidBrush(Color.Blue), drawPoin);
g.DrawString((i + 1).ToString(), new Font("Arial", 12), Brushes.Red, objectRect1);
}
}
g.Dispose();
}
pictureBox1.Image = video;
pictureBox2.Image = grayImage;
简单,在开始处理之前创建要处理的图像的位图(源)并创建副本(临时)进行处理,然后在处理时在 blob 矩形的中间获取一个点,然后使用这个
Color color = Source.GetPixel(x, y);
它将return您正在寻找的像素的颜色