Ask Your Question

Revision history [back]

having trouble to access to pixels in ROI

    Rect roi(0, 0, W / 3, H);

    Mat Roi_1 = image_gray(roi);

    int h_1 = Roi_1.rows;
    int w_1 = Roi_1.cols;

    int sum1 = 0;

    int mean1  = 0;

    int x, y;

    uchar* Data_1 = Roi_1.data;

    for (y = 0; y < h_1; y++) {
        for (x = 0; x < w_1; x++) {
            sum1 += Data_1[y * w_1, +x];
        }
    }

    mean1 = sum1 / (h_1 * w_1);

I want to get mean value of pixels on the left side of the image

so I set the ROI and read the pixels value of ROI

but it returns the upside mean values not left side

I think my code read the original image("image_gray"), not the ROI

I don't know what can I do