Ask Your Question

Put decoded base64 data into cv::Mat variable

asked 2015-07-15 08:06:10 -0500

How to decode base64 string and put it into Mat variable. Accually i can decode it using c++ but after that i don't know how to pass it to Mat. I tried searching but didn't find any clear pointed solution(so don't mark as duplicate since there are no solution to this exact question available).

I'm using chrome native messaging and i need to load image data into cv::Mat received through the STDIN.

On client-side image is encoded using javascript dataURL.

P.S:- Please don't suggest PNACL for this since it does not serve what i exactly need.

edit retag flag offensive close merge delete


I f you have decode your data you must have a buffer in memory so I think you can use a mat constructor like Mat::Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0)

LBerger gravatar imageLBerger ( 2015-07-15 09:29:32 -0500 )edit

Could you elaborate more please. with a working example. I'm trying it also but not much clear.

harshaxsoad gravatar imageharshaxsoad ( 2015-07-15 14:13:24 -0500 )edit

try to put your base64 decoded image into a vector<uchar> bytes, then Mat m = imdecode(bytes, IMREAD_ANYCOLOR);

berak gravatar imageberak ( 2015-07-16 01:17:34 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-07-15 15:19:58 -0500

LBerger gravatar image

updated 2015-07-15 15:20:36 -0500

Two possibilities : Don't use allocated memory copy each pixel in a Mat example image of type CV_16SC1

short *tmp=new short[256*256];

cv::Mat m(256,256,CV_16S);
for (int i=0;i<256;i++)
    for (int j=0;j<256;j++)
        {< short >(i,j)=tmp[i*256+j];

and another way use memory still allocated

short *tmp=new short[256*256];

cv::Mat m(256,256,CV_16S,(void *) tmp,AUTO_STEP);

In that case "The external data is not automatically deallocated, so you should take care of it."

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-07-15 08:06:10 -0500

Seen: 1,295 times

Last updated: Jul 15 '15