0
我得到當前異常:BlobCounter不支持的像素格式
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是一個攝像頭飼料:
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);
我想你應該指出你的問題中出現錯誤的代碼行 – Programmer