opencv 从内存加载图像

来源:互联网 发布:数据采集与处理官网 编辑:程序博客网 时间:2024/06/05 09:16

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_binvector<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 greyscaleprintf("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());
0 0