4
我在緩衝區jpegBuffer中有一個jpeg圖像。我試圖將它傳遞給CV :: imdecode功能:如何使用cv :: imdecode,如果圖像文件的內容在char數組中?
Mat matrixJprg = imdecode(Mat(jpegBuffer), 1);
我得到這個錯誤:
/home/richard/Desktop/richard/client/src/main.cc:108: error: no matching function for call to ‘cv::Mat::Mat(char*&)’
這是我如何填寫jpegBuffer:
FILE* pFile;
long lSize;
char * jpegBuffer;
pFile = fopen ("img.jpg", "rb");
if (pFile == NULL)
{
exit (1);
}
// obtain file size.
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
// allocate memory to contain the whole file.
jpegBuffer = (char*) malloc (lSize);
if (jpegBuffer == NULL)
{
exit (2);
}
// copy the file into the buffer.
fread (jpegBuffer, 1, lSize, pFile);
// terminate
fclose (pFile);
非常感謝。但是如果我只在緩衝區中存在圖像(例如char * jpegBuffer),並且它不作爲文件保存在磁盤上呢?那麼我如何將緩衝區發送給imdecode呢?上面的代碼只是一個小測試,但後來我只是將jpg圖像從wifi連接讀取到緩衝區而不保存到文件。 – 2010-11-24 22:35:15