I am a beginner in opencv programing, i m trying to read an image(cv::Mat) and copy its data to some vector of Uchar and then create the image back from the vector.
i.e read Mat , convert Mat to std::vector and then create a Mat from that vector again.
The vector is needed for intermediate transformation of pixel data. I reffered Convert Mat to Array/Vector in OpenCV
For the the conversion of vector-Mat.
int main()
{
Mat image = imread("c:\\cv\\abc.bmp");
std::vector<unsigned char> src_vec;
src_vec.assign(image.datastart, image.dataend);
cv::Mat dest(src_vec, true);
try {
imwrite("dest.bmp", dest);
}
catch (runtime_error& ex) {
fprintf(stderr, "Exception saving the image: %s\n", ex.what());
return 1;
}
return 0;
}
The output image seems to be garbage,how can I set the dest Mat with the vector data or is it that I am creating the vector itself in a wrong way. Any guidance will be helpful.