OpenCV does not recognize mat size

I am trying to print an image using OpenCV defining a 400x400 Mat:

plot2 = cv::Mat(400,400, CV_8U, 255);

But when I try to print the dots, something strange happens. The y coordinate only prints up to the first 100 values. That is, if I print a dot (50 100), it does not print it in the 100 / 400th part of the columns, but in the end. One way or another, 400 columns turned into 100.

For example, at startup:

for (int j = 0; j < 95; ++j){
    plot2.at<int>(20, j) = 0;
}
cv::imshow("segunda pared", plot2);

Shows this (the underlined part is the part corresponding to the code above):

IMAGE

A line that goes to 95 almost occupies all 400 points, when it should occupy only the 95/400th screen.

What am I doing wrong?

+4
source share
1 answer

cv::Mat, , CV_8U:

plot2 = cv::Mat(400,400, CV_8U, 255);

, , int, 32-, 8 . , :

for (int j = 0; j < 95; ++j){
    plot2.at<uchar>(20, j) = 0;
}

: , OpenCV ++, . , , uint16_t . OpenCV .


, cv::Mat:

for (size_t row = 0; j < my_mat.rows; ++row){
    auto row_ptr=my_mat.ptr<uchar>(row);
    for(size_t col=0;col<my_mat.cols;++col){
         //do whatever you want with  row_ptr[col]  (read/write)
    }
}
+6

All Articles