BlobCounter不支持像素格式
本文关键字:格式 像素 不支持 BlobCounter | 更新日期: 2023-09-27 18:17:06
我得到当前异常:
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);
我通过更改AForge.net的版本号修复了这个问题。我测试了多个版本,似乎当使用这段代码时,问题只出现在2.0.0版本上。