将blob图像转换为Mat图像
Convert blob images to Mat images
我的人脸识别项目使用mysql数据库。在这里,我将图像存储到表中,图像存储为blob图像。当选择回这些图像时,我需要使用文件指针将这些blob图像写入单独的图像文件,它将存储到程序所在的文件夹中。为了使用这些图像,我需要从文件夹中再次读取。然后只有我可以将这些图像用于另一个功能。但我需要直接从数据库中使用这些blob图像(当我们从数据库中选择它时,我需要将它传递给另一个函数)。这样我就可以减少从文件夹中再次读取的操作。我该如何转换bl。所以,为了将DB图像直接传递给另一个函数,我认为我们需要转换它的类型或其他什么。
void SelectImage()
{
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;
char temp[900];
char filename[50];
unsigned long *lengths;
FILE *fp;
my_ulonglong numRows;
unsigned int numFields;
int mysqlStatus = 0;
MYSQL_RES *mysqlResult = NULL;
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "root", "athira@iot", "Athira", 0, NULL, 0);
int state=mysql_query(conn, "SELECT * FROM ima1");
mysqlResult=mysql_store_result(conn);
if(mysqlResult)
{
numRows=mysql_num_rows(mysqlResult);
}
cout<<"rows:"<<numRows<<endl;
for(int i=1;i<=numRows;i++){
sprintf(temp,"SELECT data FROM ima1 WHERE id=%d",i);
sprintf(filename,"Gen_Image%d.jpeg",i);
fp = fopen(filename, "wb");// open a file for writing.
cout<<temp<<" to "<<filename<<endl;
mysql_query(conn, temp);//select an image with id
result = mysql_store_result(conn);
row = mysql_fetch_row(result);//row contains row data
lengths = mysql_fetch_lengths(result);//this is the length of th image
fwrite(row[0], lengths[0], 1, fp);//writing image to a file
cout<<"selected..."<<endl;
img.create(100,100,CV_16UC1);
memcpy(img.data,row.data,lengths);
mysql_free_result(result);
fclose(fp);
}
mysql_close(conn);
}
I tried to convert it to Mat type but it's showing error..
error is this,
error: request for member ‘data’ in ‘row’, which is of non-class type ‘MYSQL_ROW {aka char**}’
如果您的图像是使用某种图像格式(JPEG、PNG、BMP…)存储的,而不是作为原始像素数据存储的,那么您应该查看OpenCV中的imdecode函数。
如果您的数据存储为原始像素,那么您必须确保BLOB数据的内存布局可以使用OpenCV用于布局矩阵的步长功能来表示。
相关文章:
- C++:从GPU内存(cudaMemcpy2D)获取BGR图像(cv::Mat)
- 如何在 dlib 的 array2d 图像上从 dlib::rectangle 创建 cv::Mat<rgb_pixel> ?
- 如何从C 中的CV :: MAT图像中有效提取某些像素
- Mat的convertTo函数在OpenCV中将灰度图像的类型转换为CV_32F时抱怨断言错误
- 如何将OpenCV的Mat结构的部分图像矩阵加载到我自己的3x3数组中?
- 循环浏览捕获的图像 vector<cv::Mat>
- 如何将"mean_file_proto"读入OpenCV Mat,以便从平均值中减去图像以在Caffe模型中使用?
- 表示RGB图像的浮点数组的初始CV::MAT
- 将 cv::Mat 转换为穿山甲::图像
- 访问图像像素;MatIterator_<> 和 Mat::at 运算符的比较
- 为什么CV :: MAT的向量总是返回第一个图像
- 在 opencv 中从 Mat 图像创建多个子图像?尝试为每个连接的组件创建子图像
- 如何使用avcodec从OpenCV::Mat类型的jpeg图像创建视频
- 如何在 Cv::Mat 图像中放置一些文本(变量)
- 如何显示窗口大小不同的输出图像?通过使用 cv::Mat
- 如何将labview图像类型转换为opencv图像类型(或Mat)
- Haar检测-保存图像的Mat,以便获得并显示前一帧
- 在矢量Opencv中加载许多图像<Mat>
- 如何在c++ OpenCV中将图像(Mat)转换为输入数组
- 如何将NSData转换为OpenCV的图像(Mat)