我有一个C ++函数,该函数返回一个cv::Mat
值
+(cv::Mat *) makeGray:(UIImage *) image {
// Transform UIImage to cv::Mat
cv::Mat imageMat;
UIImageToMat(image, imageMat);
//Transform image to grayscale
cv::Mat grayMat;
cv::cvtColor(imageMat, grayMat, CV_BGR2GRAY);
return grayMat;
}
我在Swift中使用以下函数调用该函数:
let grayMat = OpenCVWrapper.makeGray(photoImageView.image)
我知道Swift不会导入cv::Mat
,最好的选择是什么,这样我就可以将数组拆分成一个块?
答案 0 :(得分:1)
这应该工作。只需将res = wsh.Exec("python path\pythonfile.py").StdOut.ReadAll()
转换为cv::Mat
的字节数组并返回。
malloc
然后迅速地将其设为带有计数的+ (uint8_t *)makeGray:(UIImage *)image count:(uint32_t *)count {
// Transform UIImage to cv::Mat
cv::Mat imageMat;
UIImageToMat(image, imageMat);
//Transform image to grayscale
cv::Mat grayMat;
cv::cvtColor(imageMat, grayMat, CV_BGR2GRAY);
int size = grayMat.total() * grayMat.elemSize();
void *bytes = malloc(size);
memcpy(bytes, grayMat.data, size);
*count = size;
return bytes;
}
,您可以通过调用deallocate或将其转换为字节数组来释放它。