I need to read an image with OpenCV, get its size and send it to a server so it processes the image and give it back to me the extracted features.
I have been thinking of using a vector<byte>, but I don’t understand how to copy the data to a cv::Mat. I wan’t it to be fast so I am trying to access the data with a pointer but I have a runtime exception. I have something like this.
Mat image = imread((path + "name.jpg"), 0);
vector<byte> v_char;
for(int i = 0; i < image.rows; i++)
{
for(int j = 0; j < image.cols; j++)
{
v_char.push_back(*(uchar*)(image.data+ i + j));
}
}
- Which is the best approach for this task?
Direct access is a good idea as it is the fastest for OpenCV, but you are missing the step and that is probably the reason why your program breaks. The next line is wrong:
You don’t have to increment i, you have to increment i + image.step. It will be this way: