我正在获得当前的例外:
UnsupportedImageFormatException: Unsupported pixel format of the source image.
AForge.Imaging.BlobCounter.BuildObjectsMap (AForge.Imaging.UnmanagedImage image)
AForge.Imaging.BlobCounterBase.ProcessImage (AForge.Imaging.UnmanagedImage image)
AForge.Imaging.BlobCounterBase.ProcessImage (System.Drawing.Imaging.BitmapData imageData)
AForge.Imaging.BlobCounterBase.ProcessImage (System.Drawing.Bitmap image)
cam.blobCounter (System.Drawing.Bitmap videoOutput, AForge.Imaging.BlobCounter bc) (at Assets/Scripts/cam.cs:127)
cam.Update () (at Assets/Scripts/cam.cs:69)
这是由我的blobCounter不接受我当前的图片格式引起的。为了解决这个问题,我使用了转换方法:Bitmap yellowClone = AForge.Imaging.Image.Clone(originalBm, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
但我仍然得到错误(尽管尝试了所有可用的格式)。
对于上下文,这是我的代码,originalFeedTexture是一个WebCam提要:
byte[] bytes = originalFeedTexture.EncodeToJPG();
using (var ms = new MemoryStream(bytes))
{
originalBm = new Bitmap(ms);
}
Bitmap yellowClone = AForge.Imaging.Image.Clone(originalBm, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
yellow = new Bitmap(yellowClone);
yellowFilter(yellow);
BlobCounter bc = new BlobCounter();
blobCounter(yellowClone, bc);
Rectangle[] rects = bc.GetObjectsRectangles();
if (bc.ObjectsCount >= 1)
{
Debug.Log("Swedes");
}
我的yellowFilter功能:
void yellowFilter(Bitmap videoOutput)
{
HSLFiltering yellowHslFilter = new HSLFiltering();
yellowHslFilter.Hue = new IntRange(40, 70);
yellowHslFilter.Saturation = new DoubleRange(0.3f, 0.9f);
yellowHslFilter.Luminance = new DoubleRange(0.3f, 0.8f);
yellowHslFilter.ApplyInPlace(videoOutput);
}
我的blobCounter功能:
void blobCounter(Bitmap videoOutput, BlobCounter bc)
{
bc.ObjectsOrder = ObjectsOrder.Size;
bc.ProcessImage(videoOutput);
}
编辑:我忘了提及,错误发生在以下行:blobCounter(yellowClone, bc);
答案 0 :(得分:0)
我通过更改AForge.net的版本号来修复此问题。我测试了多个版本,似乎在使用这个确切的代码时,问题只出现在2.0.0版本上。