4

I need to implement a function which takes an image and return a file say a text file containing a string of bytes. What I have done yet is :

#include <cv.h>
#include <highgui.h>
using namespace cv;

int main( int argc, char** argv )
{
cv::Mat image;
image = cv::imread("imaje.bmp");
if(image.empty())
return 0;

cv::imshow("Image", image);
cv::waitKey();

return 0;
}

Now I need to convert tha cv:Mat image to an array of bytes. Please guide me how to proceed??? Thanks in advance ... :)

Nauman Khalid
  • 41
  • 1
  • 4

1 Answers1

1

I know, it's a bit late to answer... but it may be useful for other people.

You can convert your cv::Mat to a string by doing std::string my_cv_mat(src.begin<unsigned char>(), src.end<unsigned char>());

Then you can get a char* using the .c_str() method of the string. As char and byte have the same size I guess that you just have to cast the char* to byte*.

Bastienm
  • 363
  • 2
  • 16