Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 正在将System::Drawing::Bitmap^转换为::MAT_Opencv_C++ Cli - Fatal编程技术网

Opencv 正在将System::Drawing::Bitmap^转换为::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

如何在C++/CLI中将图像从picturebox转换为::MAT

谢谢

您需要将绘图.图像转换为(假设图像确实是位图)。
然后锁定,并使用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