[Python] I'm trying to do a Color Detector in openCV but it just isn't working

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    So I am watching this tutorial, and following everything, and I'm running into this one issue. For some reason I'm getting an error in inRange saying that overload resolution failed, upperb is not a numerical tuple. Expected Ptr for argurment 'upperb'. I don't understand why lowerb works but upperb doesn't

    colorSorter.py

    import cv2 import numpy as np

    from util import get_limits

    yellow = [0, 255, 255] #Yellow in RGB colorspace cap = cv2.VideoCapture(0)

    while True: ret, frame = cap.read()

    hsvImage = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    lowerb , upperb = get_limits(color=yellow)


    mask = cv2.inRange(hsvImage, lowerb, upperb)

    cv2.imshow('frame', mask)

    if cv2.waitKey(1) & 0xFF == ord('q'):
    break


    cap.release()

    cv2.destroyAllWindows()

    util.py

    import numpy as np import cv2

    def get_limits(color): c = np.uint8([[color]]) hsvC = cv2.cvtColor(c, cv2.COLOR_BGR2HSV)

    lowerb = hsvC[0][0][0] - 10, 100, 100
    upperb = hsvC[0][0][0] + 10, 255, 255

    lowerb = np.array(lowerb,dtype=np.uint8)
    upperb = np.array(upperb,dtype=np.uint8)

    return lowerb, upperb


    I was expecting my window to pop up in a mask that will be all black expect if yellow is detected on the camera

    Continue reading...

Compartilhe esta Página