Reputation: 19
I want to set pixel value in given bmp image using CvSet2D but I want to access only the first value. Could you explain what the 4 arguments of CvSet2D are for?
For example:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
int main(int argc, char *argv[])
{
IplImage* img = cvLoadImage("initial.bmp",1);
int f = 123;
cvSet2D(img, 1, 2, f); // here is the error
//cvSet2D(img, 1, 2, cvScalar(f)); // error also this way
return 0;
}
I get an error that says:
incompatible type for argument 4 of 'cvSet2D'
I just need to set pixel value of a gray scale image, how con I do this?
Upvotes: 1
Views: 383
Reputation: 41765
You can refer to this question.
C: void cvSet2D(CvArr* arr, int idx0, int idx1, CvScalar value)
The arguments are:
To know what cvScalar
is, refer to this and
The
cvScalar
is simply a convenient container for 1, 2, 3 or 4 floating point values.
You should do something like:
uchar f = 123;
CvScalar scalar = cvGet2D(img, 1, 2);
scalar.val[0] = f;
cvSet2D(img, 1, 2, scalar);
Upvotes: 1