Opencv 正在将System::Drawing::Bitmap^转换为::MAT
如何在C++/CLI中将图像从picturebox转换为::MAT 谢谢您需要将绘图.图像转换为(假设图像确实是位图)。Opencv 正在将System::Drawing::Bitmap^转换为::MAT,opencv,c++-cli,Opencv,C++ Cli,如何在C++/CLI中将图像从picturebox转换为::MAT 谢谢您需要将绘图.图像转换为(假设图像确实是位图)。 然后锁定,并使用BitmapData的Scan0属性访问内部缓冲区 System::Drawing::Bitmap ^ bitmapFrame = safe_cast< System::Drawing::Bitmap ^ >(pictureBox1->Image); BitmapData^ bmpData = bitmapFrame->LockBit
然后锁定,并使用BitmapData的Scan0属性访问内部缓冲区
System::Drawing::Bitmap ^ bitmapFrame = safe_cast< System::Drawing::Bitmap ^ >(pictureBox1->Image);
BitmapData^ bmpData = bitmapFrame->LockBits(gcnew Rectangle(0, 0, bitmapFrame->Width, bitmapFrame->Height), System::Drawing::Imaging::ImageLockMode::ReadWrite,
bitmapFrame->Format);
try
{
void* data = bmpData.Scan0;
//use the data in the ::Mat constructor.
}
finally { bitmapFrame->UnlockBits(bmpData); }//Remember to unlock!!!
System::Drawing::Bitmap^bitmapFrame=safe\u cast(pictureBox1->Image);
位图数据^bmpData=bitmapFrame->LockBits(gcnew矩形(0,0,bitmapFrame->宽度,bitmapFrame->高度),系统::绘图::成像::图像锁定模式::读写,
位图帧->格式);
尝试
{
void*data=bmpData.Scan0;
//使用::Mat构造函数中的数据。
}
最后{bitmapFrame->UnlockBits(bmpData);}//记得解锁!!!
您可能希望使用锁位
获取指向像素值数组的指针。这样:不工作,因为这行Gdiplus::Bitmap*enhanced=pictureBox1->Image代码>,给出此错误:IntelliSense:类型为“System::Drawing::Image^”的值不能用于初始化类型为“Gdiplus::Bitmap*”的实体。当然,您应该使用C++/CLI语法System::Drawing::Bitmap
是围绕本机类的.NET包装程序Gdiplus::Bitmap
。