[英]16 bit image crashes Image.ThresholdBinary in EMGU.CV
我在下面有這個應用程序的兩個版本。 這是我寫的一個重寫,用於處理8位圖像。 8位圖像工作正常。 16位圖像導致Image.Threshold在本機OpenCV調用閾值時崩潰,返回的唯一錯誤是:
Emgu.CV.dll中發生了類型為'Emgu.CV.Util.CvException'的第一次機會異常。其他信息:OpenCV:
以下內容導致我的“手編碼” 16位圖像崩潰,也導致16位TIF圖像崩潰,通過
var img = new Image<Gray,UInt16>("test.tif");
崩潰是相同的,帶有相同的錯誤消息。
這是我的應用程序:
思考?
using System;
using System.Runtime.InteropServices;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MyUnitTest
{
[TestClass]
public class UnitTestOpenCV
{
// Set up an image with a solid rectangle in it.
private IntPtr _smallImg;
private const int Ncols = 500;
private const int Nrows = 100;
[TestInitialize]
public void Init()
{
const int n = Ncols * Nrows;
var pixels = new short[n];
_smallImg = Marshal.AllocHGlobal(n * 2);
Marshal.Copy(pixels, 0, _smallImg, pixels.Length);
for (int col = 75; col < 75 + 200; col++)
{
for (int row = 25; row < 25 + 50; row++)
{
Marshal.WriteInt16(_smallImg, 2 * (row * Ncols + col), 10000);
}
}
}
[TestCleanup]
public void Cleanup()
{
Marshal.FreeHGlobal(_smallImg);
}
[TestMethod]
public void FindingMinBoundingRectangle()
{
var img = new Image<Gray, ushort>(Ncols, Nrows, Ncols, _smallImg);
var rotatedImg = img.Rotate(20, new Gray(0), false);
var bwImg = img.ThresholdBinary(new Gray(5000), new Gray(255));
var contour = bwImg.FindContours();
var rect = contour.GetMinAreaRect();
rotatedImg.Draw(rect, new Gray(30000), 50);
rotatedImg.Save("img.tif");
AOIAlgorithmsBase.SaveImage("myImg.tif", img.MIplImage.imageData, Ncols, Nrows, Ncols);
ImageViewer.Show(rotatedImg, "Image Viewer Window");
}
}
}
實際上,即使EmguCV讀取16位圖像,大多數處理例程也需要8位或32位圖像。 從OpenCV文檔獲取閾值方法:
參數:
src –輸入數組(單通道,8位或32位浮點)。
就我而言,將所有Emgu處理和顯示的圖像轉換為8位,然后轉換回16位以tif格式保存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.