I need to set a single pixel in the Mat object to a certain value.
How to do it?
I am using openCV 2.1 with visual studio 2010.
To access individual pixels, the safest way, though not the most efficient, is to use cv::Mat::at<T>(r,c) method where r is the row of the matrix and c is the column.
CV_32F defines the depth of each element of the matrix, while. CV_32FC1 defines both the depth of each element and the number of channels.
Vec3b is the abbreviation for "vector with 3 byte entries" Here those byte entries are unsigned char values to represent values between 0 .. 255. Each byte typically represents the intensity of a single color channel, so on default, Vec3b is a single RGB (or better BGR) pixel.
If you are dealing with a uchar (CV_8U) matrix:
mat.at<uchar>(row, column, channel) = val;
In fact, there are 4 kinds of methods to get/set a pixel value in a cv::Mat object as described in the OpenCV tutorial.
The one @Régis mentioned is called On-The-Fly RA in OpenCV tutorial. It's the most convenient but also time-consuming.
Based on the tutorial's experiment, it also lists performance differences in all the 4 methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With