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

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Ich versuche einen Farbdetektor in OpenCV zu machen, aber er funktioniert einfach nicht

by Anonymous » 20 Mar 2025, 14:57

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.

Top