C# Mat与Bitmap转换疑问
cv::Mat faceMat(mydata.depthPic,mydata.faceRec);
cv::Mat faceMat_resize(this->pb_right->Height,this->pb_right->Width,faceMat.type());
cv::resize(faceMat,faceMat_resize, faceMat_resize.size(),0.0,0.0,cv::INTER_LINEAR);
cv::imshow("origin",faceMat);
cv::imshow("painted",faceMat_resize);
img=ConvertMatToBitmap(faceMat_resize);
this->pb_right->Image=img;
其中 cv::imshow能正常显示图片,但是pb_right显示不出图片。
而img=ConvertMatToBitmap(faceMat);确可以正常显示图片。
求问:
System::Drawing::Bitmap^ bmpImg; 那个^代表什么意思?这样的变量是个指针还是有具体分配的空间?
怎么样让pb_right可以正确显示faceMat_resize的内容?
下面是ConvertMatToBitmap的函数体:
System::Drawing::Bitmap^ FaceAnalyze::ConvertMatToBitmap(cv::Mat& cvImg)
{
System::Drawing::Bitmap^ bmpImg;
//检查图像位深
if(cvImg.depth() != CV_8U)
{
bmpImg = gcnew System::Drawing::Bitmap(1,1,System::Drawing::Imaging::PixelFormat::Format8bppIndexed);
return (bmpImg);
}
//彩色图像
if(cvImg.channels() == 3)
{
bmpImg = gcnew System::Drawing::Bitmap(
cvImg.cols,
cvImg.rows,
cvImg.step,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,
(System::IntPtr)cvImg.data );
}
else if(cvImg.channels() == 4)
{
bmpImg = gcnew System::Drawing::Bitmap(
cvImg.cols,
cvImg.rows,
cvImg.step,
System::Drawing::Imaging::PixelFormat::Format32bppArgb,
(System::IntPtr)cvImg.data );
}
//灰度图像
else if(cvImg.channels() == 1)
{
bmpImg = gcnew System::Drawing::Bitmap(
cvImg.cols,
cvImg.rows,
cvImg.step,
System::Drawing::Imaging::PixelFormat::Format8bppIndexed,
(System::IntPtr)cvImg.data);
}
return (bmpImg);
}
hnykkk
11 years, 11 months ago