Converting an OpenCV Image to Black and White

后端 未结 7 1493
逝去的感伤
逝去的感伤 2020-11-29 17:38

How do you convert a grayscale OpenCV image to black and white? I see a similar question has already been asked, but I\'m using OpenCV 2.3, and the proposed solution no long

相关标签:
7条回答
  • 2020-11-29 18:06

    For those doing video I cobbled the following based on @tsh :

    import cv2 as cv
    import numpy as np
    
    def nothing(x):pass
    
    cap = cv.VideoCapture(0)
    cv.namedWindow('videoUI', cv.WINDOW_NORMAL)
    cv.createTrackbar('T','videoUI',0,255,nothing)
    
    while(True):
        ret, frame = cap.read()
        vid_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        thresh = cv.getTrackbarPos('T','videoUI');
        vid_bw = cv.threshold(vid_gray, thresh, 255, cv.THRESH_BINARY)[1]
    
        cv.imshow('videoUI',cv.flip(vid_bw,1))
    
        if cv.waitKey(1) & 0xFF == ord('q'):
            break
    
    cap.release()
    cv.destroyAllWindows()
    

    Results in:

    0 讨论(0)
提交回复
热议问题