I have to process a .PNG file. The processing takes an std::vector as input and I would like to show the images as grayscale. So what I did:
Mat img = imread("Image.PNG");
cvtColor(img, img, COLOR_RGB2GRAY);
imshow(windowName,img);
This image looks fine and cout<<img<<endl;
spits out realistic values between 0 and 255.
Then I want to convert this cv::Mat to an std::vector
std::vector<double> imgvec;
imgvec.assign(img.begin<double>(), img.end<double>());
The values are now all really small (around 1e-180). Why does this happen and how can I solve it?
UPDATE:
I tried the following as suggested by @Swift-Friday Pie:
std::vector<double> imgvec;
if (img.isContinuous()){
imgvec.assign((double*)img.datastart, (double*)img.dataend);
}else{
for (int i = 0; i < img.rows; i++){
imgvec.insert(imgvec.end(), img.ptr<double>(i) + img.cols);
}
}
However, this given me the following error:
no matching function for call to 'std::vector<double>::insert(std::vector<double>::iterator, double*)'