【发布时间】:2020-12-22 19:29:42
【问题描述】:
我需要将 Drawing.Bitmap ("_MyBitmap") 转换为 EmguCV.Image
为此,我使用以下代码:
Dim nCVImage As New Emgu.CV.Image(Of Bgr, Byte)("c:\users\myuser\desktop\1.png")
MsgBox("Width: " & nCVImage.Width)'this work fine!! :-)
'Now (after the messagebox), the error is shown.
Stop'this is just some Stop statement for me to see to which point VB.NET executes the code when OpenCV throws the message. Stop is not hit. This means that the error must have occured in the very first line already.
Dim m As Mat = nCVImage.Mat
Dim imagez0 As Image(Of Gray, Byte) = m.ToImage(Of Gray, Byte)
Dim imagez1 As Image(Of Bgr, Byte) = m.ToImage(Of Bgr, Byte)
Dim imagez2 As Image(Of Gray, Byte) = imagez0.Canny(150, 60)
但是,第一行已经引发了异常“ImageSize 溢出”。
_MyBitmap 非常好。我可以在图片框中显示它。它的大小是 1200 x 1000 像素。
有人看到我的错误吗?
谢谢!
【问题讨论】:
-
IIRC,有一个重载接受一个包含数据字节的锯齿状数组和一个接受(宽度、高度、步幅、Scan0)的数组。要使用后者,请参阅:Analyze colors of an Image 中的注释(简而言之,从
Image.LockBits获取 ImageData,它包含您需要的属性。考虑 Stride,因为您正在创建特定类型的位图,所以转换可能需要) -
@jimi 我的方法有什么问题?
-
我不记得接受源
System.Drawing.Bitmap对象的Emgu.CV.Image()构造函数的重载。不过,您可以指定文件位置。 -
@Jimi 你的意思是这样吗? Dim nCVImage As New Emgu.CV.Image(Of Bgr, Byte)("c:\users\myuser\desktop\1.png") 我问是因为它抛出了同样的错误。
-
@Jimi 实际上,这很奇怪。我用一些观察来扩充我的帖子。我很确定错误发生在第一行,但我不明白为什么或哪个图像似乎加载正常。