简体   繁体   中英

Manipulating specific x,y values of a cv::Mat?

What is the simplest way to modify a direct x,y location of a cv::Mat object? I have a cv::Mat called 'temp' which has an image in it, and what if I wanted to turn each pixel pink, one by one?

I tried something of the following:

for (int i = 0; i < temp.size().width; i++)
{
    for (int j = 0; j < temp.size().height; j++)
    {
        temp.at(cv::Point(i, j)) = 255;
        cv::waitKey();
    }
}

but that won't even compile..

The way to use at in this case is temp.at<unsigned char>(i, j). Here is an example :

 Mat H(100, 100, CV_64F);
 for(int i = 0; i < H.rows; i++)
    for(int j = 0; j < H.cols; j++)
        H.at<double>(i,j)=1./(i+j+1);

For the complete description look here: http://opencv.itseez.com/modules/core/doc/basic_structures.html#mat-at

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM