Color thresholding on an opencv video

房东的猫 提交于 2019-12-06 06:17:43

Thresholding based on only the Hue component is somehow useless.
As you can see below, for a speceific Hue, the range of possible colors also includes gray colors.

Also, seeing the H,S,V channels, I can say that H channel alone can't help you. You should also use the Saturation channel:


(Hue Channel)

Though, you can see the Saturation channel can help you find the colorful areas easier:

Filtering Saturation<180 colors, would give you this:

Now you have the colorful areas. if that sidebar, is always in the picture you process, you can just filter the Value<150 in the Value channel to filter them out too:

And BTW, using cv2, your code becomes much more readable and easier to maintain:

import cv2

img = cv2.imread('image.png')
image_thr = img.copy()

imh = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
image_thr[(imh[...,1]<180) | (imh[...,2]<150)]=0

cv2.imshow('filtered',image_thr)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!