public void processImage(Bitmap bitmap)
{
Bitmap aq = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb);
Invert a = new Invert();
aq = a.Apply(aq);
AForge.Imaging.Image.FormatImage(ref aq);
IFilter filter = Grayscale.CommonAlgorithms.BT709;
aq = filter.Apply(aq);
Threshold th = new Threshold(200);
aq = th.Apply(aq);
//find the biggest blob
BlobCounter bl = new BlobCounter(aq);
int i = bl.ObjectsCount;
Blob bigblob = null;
int areaant = 0;
Blob[] blobs = bl.GetObjects(aq, true);
for (int j = 0; j < i; j++)
{
if (blobs[j].Area == 1116)
{
j++;
if (j == i)
break;
}
if (blobs[j].Area > areaant)
{
areaant = blobs[j].Area;
bigblob = blobs[j];
}
}
Bitmap bitmap2 = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bitmap2);
int radius = 1;
int x = 0;
int y = 0;
int h = 25;
Pen redPen = new Pen(Color.Red, 2);
if (i > 1)
{
Blob fil2 = bigblob;
x = fil2.CenterOfGravity.X;
y = fil2.CenterOfGravity.Y;
g.DrawEllipse(redPen,
(int)(x - radius),
(int)(y - radius),
(int)(radius * 5),
(int)(radius * 5));
}
redPen.Dispose();
g.Dispose();
pictureBox1.Image = bitmap2;
pictureBox2.Image = aq;
}
所以我想它与位图克隆方法有关,因为有时它会抛出异常。 阅读其他人和他们的灵魂的不同问题,我尝试了几件事: - 使用相同形式的不同螺纹启动每个凸轮 - 在其他解决方案中,他们认为问题在于访问位图的两个线程。所以我将表单分开,每个相机(线程)一个,然后我尝试在一个线程中使用方法procesImage(..)。没用。
非常感谢任何帮助