我似乎无法将结构的成员值插入到inRange函数中。该程序编译但阈值不能正常工作。如果我不是从结构中插入一个值,那么它可以正常工作。
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);
这很好用
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);
这不起作用。阈值图像仅显示黑色。如果我改变iLowH = orange.iLowH等的值,它也将无效。如果我改变其中一个它也不会起作用。如果我打印橙色的值,它会显示正确的值,如果我打印橙色的数据类型,它会为每个值显示int。
答案 0 :(得分:0)
orange.iHighV
未初始化。在您的代码中:
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.
两个版本(iHighH = 30
与orange.iHighH = 100
和iLowV = 0
与orange.iLowV = 100
)的实际阈值不同,因此也可能导致不同的结果。