Ask Your Question
0

impossible de decode my buffers

asked 2016-07-26 04:25:18 -0600

orpheelepoete gravatar image

I have converted an Android image into an unsigned char* buffer about to use imdecode to store it into a opencv Mat. But it's impossible to correctly show the image. I always have some Access Violation errors.

I tried to store the buffer data into a file and load it after, I also tried to use char* instead of unsigned char*, and also to read a jpeg file with opencv and encode it using

Mat jpegMat; 
jpegMat = cvLoadImage(jpegPath, 1);
cv::vector<uchar> buf;
cv::imencode(".jpg", jpegMat, buf);
res = &buf[0];

but the imdecode refuses to work. I tried every possible alternatives I found on the internet but nothing worked for me Here is the code I currently use:

cv::Mat imgbuf = cv::Mat(height, width, CV_8UC1, inputByteArray);
cv::Mat imgMat =  cv::imdecode(imgbuf, CV_LOAD_IMAGE_COLOR);

neither the "imgbuf" Mat nor the "imgMat" accepts to show itself, returning the exact same error message.

Can anyone tell me what is happening because it's been days that I tried everything without getting any results.

Thanks in advance

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-26 04:36:50 -0600

berak gravatar image

updated 2016-07-26 04:39:32 -0600

  • the input to imdecode() should be a vector<uchar>, filled like a file on disk, with headers, compressed pixels, etc. (e.g the output of imencode, bufin your previous example ), not an image

  • please use cv::imread() , not cvLoadImage() (from outdated C api)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-07-26 04:25:18 -0600

Seen: 453 times

Last updated: Jul 26 '16