CV_32FC1型Mat的opencv与Halcon数据转换

  • Post author:
  • Post category:其他


关于Opencv与Halcon的数据转换,网上资料大多是CV_8UC1或CV_8UC3型的Mat数据转换,对于CV_32FC1型的Mat转换资料很少,他们之间的转换方法如下:

Mat depth3DMatX = cv::Mat::zeros(colorImg.size(), CV_32FC1);
	Mat depth3DMatY = cv::Mat::zeros(colorImg.size(), CV_32FC1);
	Mat depth3DMatZ = cv::Mat::zeros(colorImg.size(), CV_32FC1);
	
	HObject HobjX, HobjY, HobjZ;

//Mat转Halcon
	GenImage1(&HobjX, "real", depth3DMatX.cols, depth3DMatX.rows, (Hlong)depth3DMatX.data);
	GenImage1(&HobjY, "real", depth3DMatY.cols, depth3DMatY.rows, (Hlong)depth3DMatY.data);
	GenImage1(&HobjZ, "real", depth3DMatZ.cols, depth3DMatZ.rows, (Hlong)depth3DMatZ.data);


//Halcon转Mat
	HString cType;
	Mat ImageX, ImageY, ImageZ;
	//ConvertImageType(HobjX, &HobjX, "byte");
	Hlong wid = 0;
	Hlong hgt = 0;
	HImage hImgX(HobjX), hImgY(HobjY), hImgZ(HobjZ);
	void *ptrx = hImgX.GetImagePointer1(&cType, &wid, &hgt);
	void *ptry = hImgY.GetImagePointer1(&cType, &wid, &hgt);
	void *ptrz = hImgZ.GetImagePointer1(&cType, &wid, &hgt);
	int W = wid;
	int H = hgt;
	ImageX.create(H, W, CV_32FC1);
	ImageY.create(H, W, CV_32FC1);
	ImageZ.create(H, W, CV_32FC1);

	ImageX.data = (uchar *)ptrx;
	ImageY.data = (uchar *)ptry;
	ImageZ.data = (uchar *)ptrz;



版权声明:本文为hshqing原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。