基于python的opencv实现简单的颜色分割

import cv2 as cv
from cv2 import blur
import numpy as np

bird = cv.imread("./img/bird.png")
if bird is None:
    print("路径问题")
else:
    blur = cv.blur(bird,(5,5))
    hsv = cv.cvtColor(blur,cv.COLOR_BGR2HSV)

    low_blue = np.array([55,0,0])
    high_blue = np.array([118,255,255])
    #可实现二值化功能(类似threshold()函数)可以同时针对多通道进行操作
    mask = cv.inRange(hsv,low_blue,high_blue)
    res = cv.bitwise_and(bird,bird,mask=mask)
    cv.imshow("img",res)

cv.waitKey()

不理解的地方: mask = cv.inRange(hsv,low_blue,high_blue)得到黑白图,数值的设置原则是什么
在这里插入图片描述
最终得到
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_33392383/article/details/123706352