How to find the RED color regions using OpenCV?

后端 未结 4 1267
野性不改
野性不改 2020-11-29 09:45

I am trying to make a program where I detect red. However sometimes it is darker than usual so I can\'t just use one value. What is a good range for detecting different shad

4条回答
  •  Happy的楠姐
    2020-11-29 10:44

    Red Color means Red value is higher than Blue and Green.

    So you can check the differences between Red and Blue, Red and Green.

    You can simply split RGB into individual channels and apply threshold like this.

    b,g,r = cv2.split(img_rgb)
    rg = r - g
    rb = r - b
    rg = np.clip(rg, 0, 255)
    rb = np.clip(rb, 0, 255)
    
    mask1 = cv2.inRange(rg, 50, 255)
    mask2 = cv2.inRange(rb, 50, 255)
    mask = cv2.bitwise_and(mask1, mask2)
    

    Hope it can be a solution for your problem.

    Thank you.

提交回复
热议问题