C++, Negative RGB values of pixels using OpenCV

前端 未结 4 732
旧巷少年郎
旧巷少年郎 2021-01-03 09:26

I\'m using OpenCV to iterate through an image and find the colour of each pixel, here\'s some of the code I\'m using:

IplImage* img = cvLoadImage(\"c:\\\\tes         


        
4条回答
  •  时光取名叫无心
    2021-01-03 10:13

    Try this:

    IplImage* img = cvLoadImage("c:\\test.png");
    
    for (int i = 0; i < img->height; i++)
    {
        for (int j = 0; j < img->width; j += img->nChannels)
        {
            unsigned char red = img->imageData[i * img->widthStep + j + 2];
            unsigned char green = img->imageData[i * img->widthStep + j + 1];
            unsigned char blue = img->imageData[i * img->widthStep + j];
    
            outputRGBValues(red, green, blue);
            if (red == REDCOLOUR && green == GREENCOLOUR && blue == BLUECOLOUR)
            {
                count++;
            }
        }
    }
    cvReleaseImage(&img);
    

提交回复
热议问题