Converting OpenCV Mat to array (possibly NSArray)

柔情痞子 提交于 2020-02-24 12:38:08

问题


My C/C++ skills are rusty and the documentation for OpenCV is pretty obscure. Is there a way of getting a cv::Mat data attribute converted to array/NSArray?

I want to serialize it to JSON, I know I can use the FileStorage utility to convert to YAML/XML, but that's not what I want to do.

Mat -> NSArray -> JSON

(I want to send intrinsic camera calibration values to the server)

Thanks


回答1:


you can use:

double *d = intrinsics.ptr<double>(0);

this will give you an array of 9 doubles. (it's just a cast, so be careful not to let the intrinsics Mat go out of scope.)

or

double d = intrinsics.at<double>(i,j);

to access a single element.



来源:https://stackoverflow.com/questions/20797312/converting-opencv-mat-to-array-possibly-nsarray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!