Halcon中的HObject转换到openCV的Mat
灰度图转换
将Hobject转换为openCV中的Mat,该转换过程需要用到的参数有图像的width、height与图像数据的地址
C++端代码
C#端通过调中C++的dll来将HObject转换为Mat。
实现函数
void CalibImg::genImg(unsigned char* ptr, int& width, int& height)
{
Src = Mat(height, width, CV_8UC1, ptr);
Size ksize = Src.size();
cout << "width: "<<ksize.width <<" height: "<<ksize.height<< endl;
resize(Src, Src, Size(0, 0), 0.5, 0.5);
imshow("Src", Src);
waitKey(0);
}
封装函数
SAVEROIDLL_API void bitmap2Mat(unsigned char* ptr, int& width, int& height)
{
calibImg.genImg(ptr, width, height);
}
c#端代码
导入dll
[DllImport("saveROIDLL.dll", EntryPoint = "bitmap2Mat")]
public static extern void bitmap2Mat(IntPtr ptr, ref int width, ref int height);
调用接口
void hObject2Mat()
{
HTuple pointer, type, hWidth, hHeight;
HOperatorSet.GetImagePointer1(Img, out pointer, out type, out hWidth, out hHeight);
int width = hWidth.I;
int height = hHeight.I;
xmlOp.bitmap2Mat(pointer.IP, ref width, ref height);
}