我使用mysql作为人脸识别应用程序的数据库。我在训练阶段将图像存储到数据库中,在测试阶段我将选择所有这些图像并与传入图像进行比较。由于我使用的是 mysql,因此在数据库中它将图像存储为 blob 图像。因此,当我选择它时,我需要使用文件指针将其写入单独的图像文件(应该对数据库中的每个图像执行此操作)。
sprintf(temp,"SELECT data FROM ima1 WHERE id=%d",i);
sprintf(filename,"Gen_Image%d.jpeg",i);
fp = fopen(filename, "wb");
mysql_query(conn, temp);
result = mysql_store_result(conn);
row = mysql_fetch_row(result);
lengths = mysql_fetch_lengths(result);
fwrite(row[0], lengths[0], 1, fp);
但选择图像后,该图像将存储到当前目录中。为了使用该图像,我需要再次读取该目录。但是我需要直接从该函数使用选定的图像。 我们可以将选定的图像传递到另一个函数中(而不从目录中再次读取它)吗?如果是,请给我一个例子
I tried 'imdecode'function:
std::vector<std::string> vectordata;
vectordata.push_back(row[0]);//(row[0]);
cv::Mat data_mat(vectordata,true);
cv::Mat image(cv::imdecode(data_mat,1));
cout<<"Height: " << image.rows <<" Width: "<<image.cols<<endl;
它没有显示任何错误,但它正在选择大小为零的图像,这意味着它没有选择图像。
最佳答案
尝试使用此代码进行编码和解码,对我来说工作正常,您可能需要使用 uchar
来存储数据。
Mat src=imread("src.jpg",1);
vector<uchar> buf;
imencode(".jpg",src,buf);
Mat dst=imdecode(buf,1);
imshow("src",src);
imshow("dst",dst);
关于c++ - 直接将选定的图像传递给另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23166280/