Python 无法检测具有特定颜色(RGB/HSV/HSL)的对象
我的目标是检测GTA Vice City上的车道 当我在油漆上分析这张图片时,线条就像RGB颜色空间中的[120100,45]。当我用cv2.inRange应用这个时,我不能奇怪地得到结果。我不知道该怎么办,也不知道为什么它没有给我显示任何黄色的迹象,实际上它看起来像黄色的车道 编辑1: 我发现仅获取这些行的值,它们是: 下限:0110,0 上:160195,80 这是它的照片 然而,当我试图在现场播放时,在canny和gaussblur之后使用ImageGrab模块获得这条线时,我得到: 我的目标是用Hough画线,但是,我看不到连续的线,即使在现场比赛中每次都没有线。我很困惑,以下是代码:Python 无法检测具有特定颜色(RGB/HSV/HSL)的对象,python,opencv,image-processing,opencv3.0,Python,Opencv,Image Processing,Opencv3.0,我的目标是检测GTA Vice City上的车道 当我在油漆上分析这张图片时,线条就像RGB颜色空间中的[120100,45]。当我用cv2.inRange应用这个时,我不能奇怪地得到结果。我不知道该怎么办,也不知道为什么它没有给我显示任何黄色的迹象,实际上它看起来像黄色的车道 编辑1: 我发现仅获取这些行的值,它们是: 下限:0110,0 上:160195,80 这是它的照片 然而,当我试图在现场播放时,在canny和gaussblur之后使用ImageGrab模块获得这条线时,我得到: 我的
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上使用此应用程序选择范围,以下是链接:
下面是它的解释:
您缺少中的第五个参数行。位置参数的顺序应为:
cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]])
你可以用两种方法中的一种来解决这个问题;如果行需要参数,则使用None:
或者调用要与其键一起使用的所有可选参数:
lines = cv2.HoughLinesP(image, rho, theta, threshold=..., minLineLength=..., maxLineGap=...)
你能粘贴你的代码和你得到的输出吗Pencv默认使用BGR,所以试试[45100120]左右的范围或者从BGR转换成RGB。Micka我试过了,没有解决办法that@v.coder请帮帮我,我更新了,有点紧急。我明白了。谢谢,因为你和其他喜欢你的人,我爱你
lines = cv2.HoughLinesP(image, rho, theta, threshold=..., minLineLength=..., maxLineGap=...)