您的位置:首页 > 运维架构

opencv 从内存加载图像

2015-12-08 14:46 447 查看

opencv 从内存加载图像

参考资料:

http://stackoverflow.com/questions/13705578/convert-a-string-of-bytes-to-cvmat

http://blog.csdn.net/yang_xian521/article/details/7755101

一般 OpenCV 加载图像的方法是:

char path[1024] = "/home/yuzx/2.jpg";
cv::Mat img = cv::imread(path, CV_LOAD_IMAGE_COLOR);


从内存中加载的方法是:

// img_bin 的类型是 const std::string& img_bin
vector<unsigned char> imgRawData(img_bin.begin(), img_bin.end());
cv::Mat dataMat(imgRawData, true);
// You also need to decode the image (check documentation for which types are allowed, png, jpg, depending on the OpenCV version)
cv::Mat img(cv::imdecode(dataMat, CV_LOAD_IMAGE_COLOR));  // put 0 if you want greyscale

printf("raw : w=%d, h=%d, c=%d, d=%d %d s = %d\n", img.cols, img.rows,
img.channels(), img.depth(), img.dims, (int )img.elemSize());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: