내 얼굴 인식 프로젝트에 mysql 데이터베이스를 사용하고 있습니다. 여기 테이블에 이미지를 저장하고 이미지를 BLOB 이미지로 저장합니다.이 이미지를 다시 선택하면이 BLOB 이미지를 다음과 같이 작성해야합니다. 파일 포인터를 사용하여 이미지 파일을 분리하면 프로그램이 상주하는 폴더에 저장됩니다. 그리고 해당 이미지를 사용하려면 해당 폴더에서 다시 읽어야합니다. 그 이미지 만 다른 기능으로 사용할 수 있습니다. 하지만 데이터베이스에서 직접 BLOB 이미지를 사용해야합니다 (DB에서 선택하면 다른 기능으로 전달해야합니다). 그래서 내가 폴더에서 다시 그것을 읽는 것과 같은 작업을 줄일 수 있습니다. 어떻게 bl을 변환 할 수 있습니다. 그래서 다른 기능에 직접 DB 이미지를 전달하기 때문에, 나는 우리가 그것의 유형이나 뭔가를 변환해야한다고 생각. 귀하의 이미지의 픽셀 데이터와 같은 일부 이미지 포맷 (JPEG, PNG, BMP, ...) 및하지를 사용하여 저장하는 경우blob 이미지를 매트 이미지로 변환
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**}’
사이드 노트 : 이미지 행당 하나의 쿼리를 수행하는 이유는 무엇입니까? 첫 번째'SELECT * from ima1' 쿼리 만 있으면됩니다. –