我在 iPhone 项目中使用 OpenCV。在这个应用程序中,我从 Opencv 函数接收到一个 3x3 矩阵,需要将其转换为 NSString。例如:
cv::Mat myMatrix = opencvClass.getMatrix();
NSString *matrixString = myMatrix.toNSString(); // this function does not exist actually but it is what I need
有什么建议么?
干杯,
我在 iPhone 项目中使用 OpenCV。在这个应用程序中,我从 Opencv 函数接收到一个 3x3 矩阵,需要将其转换为 NSString。例如:
cv::Mat myMatrix = opencvClass.getMatrix();
NSString *matrixString = myMatrix.toNSString(); // this function does not exist actually but it is what I need
有什么建议么?
干杯,
我想您可以将其转换为 astd::stringstream,从中提取 C 字节数组并使用它来构建您的NSString:
NSString NSStringFromCvMat(cv::Mat mat)
{
std::stringstream ss;
ss << mat;
return [NSString stringWithCString:ss.str().c_str() encoding:NSASCIIStringEncoding];
}
未经测试,但应该可以工作。编码可能是个问题。也许尝试不同的值。
不过,我认为这不是最好的解决方案,您可以通过深入研究 OpenCV 源代码找到更好、更清洁的解决方案。