我似乎无法将成员的值插入到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。
最佳答案
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
vs orange.iHighH = 100
和iLowV = 0
vs orange.iLowV = 100
)的实际阈值不同,因此也可能导致不同的结果。关于c++ - 无法将结构值插入inRange openCV,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39991476/