我正在开发 VC++ 和 OpenCV 应用程序,我正在将图像加载到 picturBox 并对其进行一些 OpenCV 操作,我将加载的图像分配给 IplImage 以对其进行处理,然后将处理后的图像再次分配到图片框中,我编写此代码以将从 openFileDialog 选择的图像加载到 IplImage 中,对图像进行二值化,然后将二值化图像重新分配回 pictureBox 代码:
const char* fileName = (const char*)(void*)
Marshal::StringToHGlobalAnsi(openFileDialog1->FileName);
IplImage *img=cvLoadImage(fileName,CV_LOAD_IMAGE_COLOR);
int width=img->width;
int height=img->height;
IplImage *grayScaledImage=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
cvCvtColor(img,grayScaledImage,CV_RGB2GRAY);
cvThreshold(grayScaledImage,grayScaledImage,128,256,CV_THRESH_BINARY);
this->pictureBox1->Image=(gcnew
System::Drawing::Bitmap(grayScaledImage->width,grayScaledImage->height,grayScaledImage->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)grayScaledImage->imageData));
但我没有找到显示二进制图像的格式,对此有任何帮助。
原图:
转换后的图像: