我在C ++中存储和读取来自SQLite数据库的图像文件,存储工作正常,但我无法使用imdecode读取并将字节转换为OpenCV cv :: Mat。这是我的代码:
std::vector<cv::Mat> images;
std::vector<string> names;
std::vector<int> ids;
sqlite3 *db;
if (sqlite3_open("fr.db", &db) != SQLITE_OK)
{
printf("Open database failed\n");
return 0;
}
sqlite3_stmt *statement;
const char* sql = "SELECT * FROM Friends";
if (sqlite3_prepare_v2(db, sql, strlen(sql), &statement, 0) != SQLITE_OK)
{
printf("Open database failed\n");
return 0;
}
int result = 0;
while (true)
{
result = sqlite3_step(statement);
if (result == SQLITE_ROW)
{
int id = sqlite3_column_int(statement, 0);
ids.push_back(id);
int size = sqlite3_column_bytes(statement, 1);
std::vector<byte> data((byte)sqlite3_column_blob(statement, 1), size);
images.push_back(cv::imdecode(data, CV_LOAD_IMAGE_COLOR));
char* name = (char*)sqlite3_column_text(statement, 2);
names.push_back(name);
}
else
{
break;
}
}
问题是imdecode没有构建cv :: Mat但它返回空的.. 提前谢谢。