[英]OpenCV inRange() function
I try to run the following code: 我尝试运行以下代码:
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;
int main() {
VideoCapture cap;
cap.open(0);
while (1) {
Mat src;
Mat threshold;
cap.read(src);
inRange(src, Scalar(0, 0, 0), Scalar(255, 0, 0), threshold);
imshow("thr", threshold);
imshow("hsv", src);
waitKey(33);
}
return 0;
}
But it seems like it doesn't filter because there is only a blank window appearing when I run the code. 但它似乎没有过滤,因为我运行代码时只出现一个空白窗口。
How to get that code to detect red colors? 如何让代码检测红色?
You have to modify inRange
function like this: 您必须像这样修改
inRange
函数:
inRange(src, Scalar(0, 0, 0), Scalar(255, 255, 255), threshold);
If you try to threshold just the first channel (the blue channel), then you have to make other channels free, so set it to 0
in lawerb
and its dtype
, usually 255
for np.uint8
如果您尝试门槛只是第一个通道(蓝色通道),那么你就必须做出其他渠道免费的,所以将其设置为
0
的lawerb
和dtype
,通常255
为np.uint8
Eg 例如
inRange(src, Scalar(0, 50, 0), Scalar(255, 100, 255), threshold);
this line will compare the 2nd channel (the green channel) and ignore others. 此行将比较第二个频道(绿色频道)并忽略其他频道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.