OpenCV InRange参数 [英] OpenCV InRange parameter

查看:174
本文介绍了OpenCV InRange参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android上使用OpenCV实时查找特定颜色的圆圈.我的第一步是仅保留与我要查找的定义颜色相对应的像素(在此示例中为红色或绿色). 示例图片.

I'm using OpenCV on Android to find circles of specific colour's in real time. My first step is to keep only pixels which corresponds to my defined color i'm looking for (red or green in this example). Example Image.

为此,我正在使用方法 inRange().

For this purpose i'm using the method inRange().

这是我的问题:下限/上限颜色参数需要哪种颜色模型(RGB,BGR,HSV,..)?并且:关于自然亮度变化来定义这些颜色界限的良好实践是什么?

Here is my Question: What kind of color model (RGB, BGR, HSV, ..) is required as lower-/upper-bound color parameter's? And: what is a good practice to define these color bounds in respect to natural brightness changes?

matRgba = inputFrame.rgba();

Scalar lowerColorBound = Scalar(0.0, 0.0, 0.0); // Blue, Green, Red?
Scalar upperColorBound = Scalar(0.0, 0.0, 0.0);

// convert to HSV, necessary to use inRange()
Imgproc.cvtColor(matRgba, matRgba, Imgproc.COLOR_RGB2HSV);

// keep only the pixels defined by lower and upper bound range
Core.inRange(matRgba, lowerColorBound, upperColorBound, matRgba);

推荐答案

OpenCV中inRange(src, lowerb, upperb, dst)函数所需的颜色模型是HSV.

The required color model for the inRange(src, lowerb, upperb, dst) function in OpenCV is HSV.

lowerbupperb参数以HSV格式指定所需的上下限.在OpenCV中,对于HSV,色相范围为[0,179],饱和度范围为[0,255],值范围为[0,255].

The lowerb and upperb parameters specify the required lower and upper color bounds in the HSV format. In OpenCV, for HSV, Hue range is [0,179], Saturation range is [0,255] and Value range is [0,255].

对于对象跟踪应用程序,一种可能的做法(如官方文档)来定义这两个颜色范围可以是:

For object tracking applications a possible practice (as suggested in the official documentation) to define these two color bounds can be:

  1. 从一种颜色开始,以RGB格式进行跟踪.
  2. 将颜色转换为HSV格式.假设(H, S, V)为它的值.
  3. 将值(H - deltaH, minS, minV)分配给lowerb,将值(H - deltaH, maxS, maxV)分配给upperb.
  1. Start from a color to track in RGB format.
  2. Convert the color to the HSV format. Let (H, S, V) be its value.
  3. Assign the value (H - deltaH, minS, minV) to lowerb and the value (H - deltaH, maxS, maxV) to upperb.

在步骤3中定义的参数的可能起始值可以是:

Possible starting values for the parameters defined in step 3 can be:

  • deltaH = 10
  • minS = 100minV = 100
  • maxS = 255maxV = 255
  • deltaH = 10
  • minS = 100, minV = 100
  • maxS = 255, maxV = 255

然后,您可以根据需要调整它们以缩小或扩大H,S,V间隔.

Then you can adjust them to narrow down or enlarge the H, S, V intervals as needed.

这篇关于OpenCV InRange参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆