无法检测到具有特定颜色的对象 (RGB/HSV/HSL)
Can't Detect Object with a Specific Color (RGB/HSV/HSL)
当我在 paint 上分析这张图片时,线条就像 [120,100,45] 的 RGB 颜色 space。当我用 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 上使用此应用程序选择范围,这里是 link:http://answers.opencv.org/question/134248/how-to-define-the-lower-and-upper-range-of-a-color/
这是带有解释的样子:
您缺少 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=...)
当我在 paint 上分析这张图片时,线条就像 [120,100,45] 的 RGB 颜色 space。当我用 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 上使用此应用程序选择范围,这里是 link:http://answers.opencv.org/question/134248/how-to-define-the-lower-and-upper-range-of-a-color/
这是带有解释的样子:
您缺少 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=...)