Ask Your Question

dcole's profile - activity

2013-06-07 12:29:11 -0600 received badge  Editor (source)
2013-06-07 11:05:03 -0600 asked a question Need output jpeg to match size of input jpeg

Hello,

I am using the sample facial detection code to process images for face detection.

I have modified it a bit to use data from memory as opposed to reading data from a file:

     std::vector<unsigned char> data(jpegBuffer, jpegBuffer + lSize);
     Mat test = cv::imdecode(Mat(data), -1);
     IplImage ipl = test;
     IplImage tempIpl;
     img = &ipl;
     memcpy(&tempIpl, &ipl, sizeof(IplImage));
     temp_img=&tempIpl;
     detectFacialFeatures(img,temp_img,1);

Where jpegBuffer in this case is an unsigned char array.

The problem is after processing I want to take the modified image (still pointed to by test), and output a jpeg that is the same byte-size as that input jpegBuffer was.

However, when I do the output with im::decode, I have to pass in a quality parameter that affects the size of the output buffer:

vector<int> param = vector<int>(2);

param[0]=CV_IMWRITE_JPEG_QUALITY;
param[1]=50;//default(95) 0-100

std::vector<unsigned char> endData;
endData.reserve(lSize);
cv::imencode(".jpg", test, endData, param);
memcpy( retbuffer, &endData[0], lSize );

retbuffer is a new unsigned char array that is the same size of jpegBuffer Is there a way to do what I am referring to?