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 ... :)

1 Answer 1

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*.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.