我人臉識別project.Here我存儲圖像到表和圖像存儲爲BLOB images.when選擇相應的圖片後,我需要寫這些斑點圖像使用文件指針分離圖像文件,並將其存儲到程序所在的文件夾中。爲了使用這些圖像,我需要從該文件夾中再次讀取它。然後,只能將該圖像用於其他功能。但是我需要直接從數據庫中使用這些blob圖像(當我們從數據庫中選擇它時,我需要將它傳遞給另一個函數)。這樣我就可以減少像從文件夾中再次讀取操作。如何轉換bl。因此,將數據庫圖像直接傳遞給另一個函數,我認爲我們需要將其轉換爲類型或其他。轉換BLOB圖像太我使用MySQL數據庫的圖像
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", "[email protected]", "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**}’
附註:爲什麼你要對每個圖像行進行一個查詢?你的第一個'從ima1'查詢應該是你所需要的。 –