【问题标题】:Can't Detect Object with a Specific Color (RGB/HSV/HSL)无法检测具有特定颜色的对象 (RGB/HSV/HSL)
【发布时间】:2017-06-05 18:34:51
【问题描述】:

我的目标是检测 GTA Vice City 上的车道。

当我在油漆上分析这张图片时,线条就像 RGB 颜色空间中的 [120,100,45]。当我将它与 cv2.inRange 一起应用时,我无法得到奇怪的结果。我不知道该怎么办,也不知道为什么它没有向我显示任何黄色(实际上它看起来像黄色)车道的迹象。

编辑1:

我发现只有这些行的值,它们是: 较低:0,110,0 上:160,195,80

这是它的照片,

但是,当我尝试使用 ImageGrab 模块(在 canny 和 gaussblur 之后)在现场播放中获得这条线时,我得到:

我的目标是用 HoughProbabilistic 画线,但是,我看不到连续的线,即使每次现场比赛都没有线。我很困惑,这是代码:

   def process_img(image):
    lower_yellow = np.array([0, 110, 0])
    upper_yellow = np.array([160, 195, 80])
    # yellow color mask
    processimagehsl = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    yellow_mask = cv2.inRange(processimagehsl, lower_yellow, upper_yellow)  # and we are masking it
    masked = cv2.bitwise_and(image, image, mask=yellow_mask)  # and then we combine it with original image
    # turned into gray
    processimagecanny = cv2.Canny(masked, threshold1=150,
                                  threshold2=300)  # with canny edge detection method, we detect edges
    # of only our yellow lines' edges. We used masking
    # at the beginning of the code because of this.
    processimagegauss = cv2.GaussianBlur(processimagecanny, (5, 5), 0)  # This'Ll fix some in order to avoid noises
    processedimage = regionofinterest(processimagegauss)  # Let's get back to our predetermined region
    lines = cv2.HoughLinesP(processedimage, 1, np.pi / 180, 180, 0, 0)

    return processedimage

已解决

您可以在 OpenCv 上使用此应用程序选择范围,这是链接:http://answers.opencv.org/question/134248/how-to-define-the-lower-and-upper-range-of-a-color/

下面是它的解释:

【问题讨论】:

  • 你能粘贴你的代码和你得到的输出吗
  • opencv 默认使用 BGR,因此请尝试 [45, 100, 120] 左右的范围或从 BGR 转换为 RGB。
  • Micka 我试过了,没有解决办法
  • @v.coder 请大家帮忙,我更新了,有点急。

标签: python opencv image-processing opencv3.0


【解决方案1】:

您在cv2.HoughLinesP() 中缺少第五个参数lines。位置参数期望顺序:

cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]])

您可以通过以下两种方法之一解决此问题;要么使用None,其中的参数应该是lines

lines = cv2.HoughLinesP(image, rho, theta, threshold, None, minLineLength, maxLineGap)

或调用您想要与它们的键一起使用的所有可选参数:

lines = cv2.HoughLinesP(image, rho, theta, threshold=..., minLineLength=..., maxLineGap=...)

【讨论】:

  • 嗯,我明白了。谢谢,爱 SoF 因为你和其他像你一样的人
猜你喜欢
  • 2011-02-04
  • 2011-03-26
  • 2011-01-22
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
  • 2014-06-19
相关资源
最近更新 更多