如何访问 OpenCV 中的每个像素,执行操作并将新信息 return 添加到图像中?

How can I access each pixel in OpenCV, perform an operation and return the new information to the image?

我正在尝试访问图像的每个像素以执行操作,然后 return 将其返回到图像,自从我完成此操作以来,有人知道如何做,但它标记我编译的时候错了。

 #include <opencv2/opencv.hpp>
 #include <opencv2/highgui/highgui.hpp> 
 #include <stdio.h>

 using namespace cv;
 using namespace std;
 int main( int argc, char** argv ){

    char* source_window = "Source image";
    Mat nueva;
    Mat img = imread("img.jpg",CV_LOAD_IMAGE_COLOR);
    unsigned char *input = (unsigned char*)(img.data);

    int i,j,b;
    for(int i = 0;i < img.cols;i++){
        for(int j = 0;j < img.rows;j++){
           b = input[i+1][j+1] ;
           nueva[i][j] = b;
         }
     }

     imshow( source_window, nueva );

 }

我认为您可以使用此代码

 int nl= image.rows; 
 int nc= image.cols * image.channels();
 for (int j=0; j<nl; j++) {
    uchar* data= image.ptr<uchar>(j);
    for (int i=0; i<nc; i++) {
       data[i]= data[i]/div*div + div/2;
    }
 }