Color Filters Problems [closed]

asked 2019-02-27 03:44:45 -0600

emir gravatar image

updated 2020-10-21 05:58:50 -0600

Hello everyone

Nowadays I am struggling with basic colour detection method. As you now, Basically we are using HSV colour space to detect which colourful marker we want to detect or track. But I am working on a cap which is wearable to Human Head. The cap has a 2 different colourful marker first one is blue second is red. I have no problem to detect blue one but When cap wearing from a person who has a little red face my red colour detects function only detect a face. I want to eliminate that I also tried to create an if statement to classify contours because of the red marker has [10* 2 = 20 cm] small area.

The first function is below for red point detection.

  def red(croped):
    redLower = (4, 100, 100)
    redUpper = (179, 255, 255)
    #hsv=croped
    hsv = cv2.cvtColor(croped, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, redLower, redUpper)
    output = cv2.bitwise_and(hsv, hsv, mask = mask)

    cv2.imshow("images", np.hstack([hsv, output]))
    cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
            cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if imutils.is_cv2() else cnts[1]
    c = max(cnts, key=cv2.contourArea)
    extLeft = tuple(c[c[:, :, 0].argmin()][0])
    extRight = tuple(c[c[:, :, 0].argmax()][0])
    extTop = tuple(c[c[:, :, 1].argmin()][0])
    extBot = tuple(c[c[:, :, 1].argmax()][0])
    cv2.drawContours(image, [c], -1, (0, 255, 255), 2)
    cv2.circle(image, extLeft, 6, (0, 0, 255), -1)
    cv2.circle(image, extRight, 6, (0, 255, 0), -1)
    cv2.circle(image, extTop, 6, (255, 0, 0), -1)
    cv2.circle(image, extBot, 6, (255, 255, 0), -1)
# show the images
    #cv2.imshow("images", np.hstack([image, output]))

    return extLeft,extRight,extTop,extBot

https://paste.ubuntu.com/p/dSpJKVrvFW/

Second one is a different way to detect red areas I apply 2 hsv filter for hole range.

  def hsv(croped):
    img_hsv=cv2.cvtColor(croped, cv2.COLOR_BGR2HSV)

    # lower mask (0-10)
    lower_red = np.array([0,50,50])
    upper_red = np.array([10,255,255])
    mask0 = cv2.inRange(img_hsv, lower_red, upper_red)

    # upper mask (170-180)
    lower_red = np.array([170,50,50])
    upper_red = np.array([180,255,255])
    mask1 = cv2.inRange(img_hsv, lower_red, upper_red)

    # join my masks
    mask = mask0+mask1

    # set my output img to zero everywhere except my mask orjinal görüntü
    output_img = croped.copy()
    output_img[np.where(mask==0)] = 0

    # or your HSV image, which I *believe* is what you want # hsv görüntüsü
    output_hsv = img_hsv.copy()
    output_hsv[np.where(mask==0)] = 0

    cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
            cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if imutils.is_cv2() else cnts[1]
    c = max(cnts, key=cv2.contourArea)
    print(c)


    # determine the most extreme points along the contour
    extLeft = tuple(c[c[:, :, 0].argmin()][0])
    extRight = tuple(c[c[:, :, 0].argmax()][0])
    extTop = tuple(c[c[:, :, 1].argmin()][0])
    extBot = tuple(c[c[:, :, 1].argmax()][0])
    cv2.drawContours(croped, [c], -1, (0, 255, 255), 2)

    return extLeft,extRight,extTop,extBot

https://paste.ubuntu.com/p/s6f5WrXqZW/

I am waiting your feedback , I found new colour space on web, called OHTA but I ... (more)

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-16 16:51:38.072448

Comments

can you put the code into your question, not on an external bin (where it will expire), please ?

berak gravatar imageberak ( 2019-02-28 01:58:45 -0600 )edit
1

For sure I did it.

emir gravatar imageemir ( 2019-03-02 15:12:17 -0600 )edit