I read an image. Then, I would like to access 39th element of the image.
cv::Mat img = cv::imread( "lena.png",cv::IMREAD_GRAYSCALE);
float * ptr = (float*)refImage.data;
printf(" %d \n", refImage.data[39]);
printf(" %f \n", *(ptr + 39));
Output is shown below:
110
274415818481933370785792.000000
I've read that we can access using float pointer. Can you tell me what is wrong?
I found out that it is not always float pointer:
According to the matrix type, the pointer will have a different template.
For CV_8UC1: uchar* ptr = image.ptr(r);
For CV_8UC3: cv::Vec3b* ptr = image.ptr<cv::Vec3b>(r);
For CV_32FC1: float* ptr = image.ptr(r);
For CV_32FC3: cv::Vec3f* ptr = image.ptr<cv::Vec3f>(r);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.