Ask Your Question

Revision history [back]

write pixel to mat

I want to manually set every pixel's R,G, and B floating point values to 0.4. When I run the following code I get an error. What am I doing wrong?

The error at run-time is:

* Error in `./program': free(): invalid next size (fast): 0x00000000019f9080 * Aborted

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    Mat imageF(36,36, CV_32F);
    int i = 0;
    int j = 0;
    float blue = 0.0;
    float green= 0.0;
    float red= 0.0;
    Vec3f intensity;

    for(j=0; j<imageF.cols; j++)
        {
            for(i=0; i<imageF.rows; i++)
                {
                    intensity = imageF.at<Vec3f>(j, i);
                    //blue = intensity.val[0];
                    //green = intensity.val[1];
                    //red = intensity.val[2];

                    blue = red = green = 0.4;

                    intensity.val[0] = blue;
                    intensity.val[1] = green;
                    intensity.val[2] = red;

                    imageF.at<Vec3f>(j, i) = intensity;
                }
        }
    imshow("Output", imageF);

    waitKey(0);
    return 0;
}