Bootstrap

OpenCV中Mat类型与C#中Bitmap类型的转换

OpenCV中Mat类型与C#中Bitmap类型的转换

OpenCV类型中图像的处理

	readImage = imread(imgpath, IMREAD_GRAYSCALE);
	threshold(readImage,outputImage, 0, 255, THRESH_BINARY | THRESH_OTSU);
	tmp =	outputImage.clone();
	uchar*  imgdata = new uchar[tmp.rows*tmp.cols * 3];
	imgdata = tmp.data;
	width = tmp.size().width;
	height = tmp.size().height;
	step = tmp.step;
	data = imgdata;

关键点:最后的data数据类型为uchar*& 类型,定义如下:
char*& data;
若是只定义为char*类型,则只指向了图像头部指针,在外层调用时为空。

C#类型中图像的处理

[DllImport("XXXXXXXX.dll")]
public static extern void Run(string imgpath, out int width, out int height, out int step,out IntPtr data);
//运行方法
IntPtr imgData;
Run(imgPath,out width,out height,out step,out imgData);
Bitmap bmp = new Bitmap(width, height, step, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, imgData);
bmp.Save("D:/0803.bmp");

关键点:函数参数的定义,定义为引用的指针。

;