0

I can't seem to get this to work. I'm trying to get the pixel value of an image but first need to change the color of the image, but since I cannot use int or just Mat because the values are not whole numbers, I have to use <float> and because of that errors pop up when I try to run this on the cmd.

int main(int argc, char **argv)
{

    Mat img = imread(argv[1]);
    ofstream myfile;

    Mat_<float> MatBlue = img;
        int rows1 = MatBlue.rows;
        int cols1 = MatBlue.cols;
        for(int x = 0; x < cols1; x++) {
            for(int y = 0; y < rows1; y++) {
                float val = MatBlue.at<cv::Vec3b>(y, x)[1];
                MatBlue.at<cv::Vec3b>(y, x)[0] = val + 1;

            }
        }
}
Paul R
  • 208,748
  • 37
  • 389
  • 560
user1371674
  • 3
  • 1
  • 3

1 Answers1

1

To achieve your goal, i.e. type conversion, use cv::Mat::convertTo.

Example: img.convertTo(MatBlue, CV_32F) or img.convertTo(MatBlue, CV_32F, 1.0/255.0) (to have values normalized between 0 and 1).

You are mixing char and float pointer types in your code.

sansuiso
  • 9,259
  • 1
  • 40
  • 58