美文网首页
opencv python版-lesson 05

opencv python版-lesson 05

作者: writ | 来源:发表于2019-10-09 22:06 被阅读0次

    颜色变换器

    import cv2
    import numpy as np 
    
    def nothing(x):
        pass
    
    img = np.zeros((300,512,3),np.uint8)
    cv2.namedWindow('image')
    
    cv2.createTrackbar('R','image',0,255,nothing)
    cv2.createTrackbar('G','image',0,255,nothing)
    cv2.createTrackbar('B','image',0,255,nothing)
    
    switch='0:OFF\n1:ON'
    cv2.createTrackbar(switch,'image',0,1,nothing)
    
    while(1):
        cv2.imshow('image',img)
        k=cv2.waitKey(1)&0xFF
        if k == 27:
            break
        r = cv2.getTrackbarPos('R','image')
        g = cv2.getTrackbarPos('G','image')
        b = cv2.getTrackbarPos('B','image')
        s = cv2.getTrackbarPos(switch,'image')
    
        if s==0:
            img[:]=0
        else:
            img[:]=[b,g,r]
    cv2.destroyAllWindows()
    

    相关文章

      网友评论

          本文标题:opencv python版-lesson 05

          本文链接:https://www.haomeiwen.com/subject/vmsnpctx.html