// 指针读取 Mat result = Mat::zeros(src_copy.size(), src_copy.type()); int blue = 0, green = 0, red = 0; int gray; for (int row = 0; row < height; ++row) { // curr_row为第row行的首地址,遍历时,前三个字节表示的是第一个像素的BGR值, // 注意BGR值顺序,接下来三个字节是第二个像素的值。 uchar *curr_row = src_copy.ptr<uchar>(row); uchar *result_row = result.ptr<uchar>(row); for (int col = 0; col < width; ++col) { if (ch == 3) { blue = *curr_row++; green = *curr_row++; red = *curr_row++;
src = cv.imread("../images/liuyifei_1.png") cv.namedWindow("input", cv.WINDOW_AUTOSIZE) cv.imshow("input", src) h, w, ch = src.shape print("h , w, ch", h, w, ch) for row in range(h): for col in range(w): b, g, r = src[row, col] b = 255 - b g = 255 - g r = 255 - r src[row, col] = [b, g, r] cv.imshow("output", src)