1 | initial version |
1 - Not sure why that is happening, but here are a few possibilities:
OpenCV's Mat deals automatically with memory allocation so you don't have to do it yourself. The reason why it is working when you replace vector for Mat is because of that automatic memory handling that is going on. Make sure your Mat M is of type CV_64F to match your vector<double>.
OpenCV stores pixels in memory in form of a 1D array (not 2D). So, a cv::Mat is actually a very big row that is later handled in a way to mimic a 2-D array. It is likely that Mat::col() operator returns a non-continuous Mat, so the behaviour when trying to copy it into a std::vector is undefined. Verify if M.isContinuous() returns true. If it doesn't, you can make it continuous by calling M = M.clone() (which creates a new space on memory for Mat).
2 - Yes, if you want to convert mat to make it "visualizable" you must normalize it before converting. In a Mat of CV_64F type, any value above 255 will stay 255 when you convert it to 8-Bit. So, you need to call cv::normalize(Source, Destination, 0, 255, CV_MINMAX). This will transform Mat so that all values are between 0 and 255. Then you can transform it into 8-bit and visualize it.
3 - I've never compared, but I believe there is no difference in processing a vector or a Mat. As I wrote before, a cv::Mat is just a big array. Nothing like making the real tests though.