Andira Andira - 1 month ago 15
C Question

cannot insert struct values to inRange openCV

I can't seem to insert the value of a member on a struct to an inRange function. The program compiles but the threshold is not working as it suppose to. If I insert a value not from a struct it works well.

struct objects{
int iLowH;
int iHighH;

int iLowS;
int iHighS;

int iLowV;
int iHighV;

Point coordinate;
};


int iLowH = 0;
int iHighH = 30;

int iLowS = 182;
int iHighS = 255;

int iLowV = 0;
int iHighV = 255;

int refArea=10000;

orange.iLowH = 0;
orange.iHighH = 100;
orange.iLowS = 182;
orange.iHighS = 255;
orange.iLowV = 100;
orange.iLowH = 255;

inRange(hsvImage, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), threshold);

imshow("hsv",threshold);


This works well

struct objects{
int iLowH;
int iHighH;

int iLowS;
int iHighS;

int iLowV;
int iHighV;

Point coordinate;
};


int iLowH = 0;
int iHighH = 30;

int iLowS = 182;
int iHighS = 255;

int iLowV = 0;
int iHighV = 255;

int refArea=10000;

orange.iLowH = 0;
orange.iHighH = 100;
orange.iLowS = 182;
orange.iHighS = 255;
orange.iLowV = 100;
orange.iLowH = 255;

inRange(hsvImage, Scalar(orange.iLowH, orange.iLowS, orange.iLowV), Scalar(orange.iHighH, orange.iHighS, orange.iHighV), threshold);

imshow("hsv",threshold);


this does not work. The threshold image only shows black. if I change the value of iLowH = orange.iLowH and so on it will not work either. if I change one of them it will not work also. If I print the value of orange it shows the correct values, and if I print the data type of orange it shows int for each of them.

Answer

orange.iHighV is not initialized. In your code:

orange.iLowH = 0;
orange.iHighH = 100;
orange.iLowS = 182;
orange.iHighS = 255;
orange.iLowV = 100;
orange.iLowH = 255;
//      ^^ overwrites previous value 0, should probably be iHighV instead.

The actual thresholds differ between the two versions (iHighH = 30 vs orange.iHighH = 100 and iLowV = 0 vs orange.iLowV = 100), so that could also lead to different results.

Comments