OpenCV Python - Set background colour

前端 未结 5 648
囚心锁ツ
囚心锁ツ 2020-12-16 05:16

I am trying to remove a greyish background from a photo and replace it with a white one

so far I have this code:

image = cv2.imread(args[\"image\"])
         


        
5条回答
  •  无人及你
    2020-12-16 05:55

    First convert to GRAY and then threshold with cv2.threshold and then use numpy masking...

    ret, thresh = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), 220, 255, cv2.THRESH_BINARY)
    img[thresh == 255] = 255
    

    If need black background set RHS to zero instead of 255

提交回复
热议问题