我需要实现一个函数,它接收包含图像字节的字符串(通过boost套接字连接接收),然后将信息转换为OpenCV cv :: Mat。
我还知道图像的宽度、高度和以字节为单位的大小。我的函数如下所示:
void createImageFromBytes(const std::string& name, std::pair<int,int> dimensions, const std::string& data)
{
int width,height;
width = dimensions.first;
height = dimensions.second;
//convert data to cv::Mat image
std::string filepng = DATA_PATH"/" + name +".png";
imwrite(filepng, image);
}
哪种方法是最好的?OpenCV是否有从字符串构造Mat的构造函数?