使用`cv:inRang‘(OpenCV)选择正确的上、下HSV边界进行颜色检测我有一张咖啡罐的图片,上面有一个橙色的盖子,我想找到这个位置。在这里.gcolor 2实用程序显示位于盖子中心的HSV为(22,59,100)。问题是如何选择颜色的界限?我试过min=(18,40,90)和max=(27,255,255),但结果出乎意料。下面是Python代码:import cv
in_image = 'kaffee.png'
out_image = 'kaffee_out.png'
out_image_thr = 'kaffee_thr.png'
ORANGE_MIN = cv.Scalar(18, 40, 90)
ORANGE_MAX = cv.Scalar(27, 255, 255)
COLOR_MIN = ORANGE_MIN
COLOR_MAX = ORANGE_MAX
def test1():
frame = cv.LoadImage(in_image)
frameHSV = cv.CreateImage(cv.GetSize(frame), 8, 3)
cv.CvtColor(frame, frameHSV, cv.CV_RGB2HSV)
frame_threshed = cv.CreateImage(cv.GetSize(frameHSV), 8, 1)
cv.InRangeS(frameHSV, COLOR_MIN, COLOR_MAX, frame_threshed)
cv.SaveImage(out_image_thr, frame_threshed)
if __name__ == '__main__':
test1()
3 回答
小唯快跑啊
TA贡献1863条经验 获得超2个赞
HSV
hsv-colormap
Hue
Saturation
S = 255
V = 255
.
H
S
H :[10, 25], S: [100, 255], and V: [20, 255]
cv2.inRange(hsv,(10, 100, 20), (25, 255, 255) )
#!/usr/bin/python3 # 2018.01.21 20:46:41 CST import cv2 img = cv2.imread("test.jpg") hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv,(10, 100, 20), (25, 255, 255) ) cv2.imshow("orange", mask);cv2.waitKey();cv2.destroyAllWindows()
添加回答
举报
0/150
提交
取消