簡體   English   中英

在C#中使用emguCV轉換為灰度

[英]Conversion to grayscale using emguCV in C#

我是EmguCV的新手。 我想將rgb圖像轉換為灰度圖像。 對於轉換,我使用了代碼

Image<Gray,byte> grayImage = ColordImage.Convert<Gray, byte>();

現在,當我在C#中編譯此代碼時,它沒有給出任何錯誤,但是當我運行它時,幾秒鍾之后,它在這行代碼中給出了異常,OpenCV不支持這種類型的轉換。 現在任何人都可以幫我解決這個問題。

關心Amal

它可能取決於ColordImage的顏色類型。

例如,這有效:

Capture cap = new Capture(1);
Image <Bgr,Byte> ColordImage = cap.QueryFrame();
Image <Gray,Byte> grayImage = ColordImage.Convert<Gray, Byte>();
imageBox1.Image = grayImage;

如果您可以提供更多代碼,那么正在發生的事情可能會更加明顯。

您應該將opencv_imgproc220.dll(如果使用emgu cv 2.2.1.1150)粘貼到項目bin / debug文件夾中。

或者,如果您不想使用Convert (例如,如果您的ColoredImage是其他數據類型,如IntPtr),則有許多構造函數可用,例如:

Image<Gray, byte> grayFrame = new Image<Gray, byte>(width, height, stride, imageData);

這是一個完整的清單:
http://www.emgu.com/wiki/files/2.1.0.0/html/cb45d54d-ebce-44b6-0352-3e1105c0862a.htm

在emgu Wiki上還有一些更多的例子(包括Convert的用法): http ://www.emgu.com/wiki/index.php/Working_with_Images

一種簡單的方法是在構造函數中傳遞彩色圖像的BitMap;

Image<Bgr, byte> inputImage = //your original bgr image
Image<Gray, Byte> result = new Image<Gray,byte>(inputImage.Bitmap);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM