Ich versuche einen Farbdetektor in OpenCV zu machen, aber er funktioniert einfach nichtPython

Python-Programme
Anonymous
 Ich versuche einen Farbdetektor in OpenCV zu machen, aber er funktioniert einfach nicht

Post by Anonymous »

Ich schaue mir dieses Tutorial an und folge alles, und ich treffe dieses eine Ausgabe. Aus irgendeinem Grund bekomme ich einen Fehler in Inrange und sagen, dass die Überlastauflösung fehlgeschlagen ist, Upperb ist kein numerisches Tupel. Erwartete PTR für Argurment 'Upperb'. Ich verstehe nicht, warum LowerB funktioniert, aber Upperb nicht.

Code: Select all

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) == ord('q'):
break

cap.release()

cv2.destroyAllWindows()
< /code>
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
Ich hatte erwartet, dass mein Fenster in einer Maske auftaucht, die nur schwarz ist, außer wenn Gelb auf der Kamera erkannt wird.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post