I am trying to create with my partrners a semaphore detector, but on my partner's pc it gives the following problem:
exception has ocurred: error x
OpenCV(4.5.5) D:\a\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv: :CascadeClassifier: :detectMultiScale'
File "C:\Users\marce\OneDrive\Escritorio\P.E.D.R.O\Detector de Objetos y Coloes\version_final_detector.py", line 17, in <module> toy=semaforoClassif.detectMultiScale(frameHSV,scaleFactor=5,minNeighbors=400,minSize=(70,78))
the complete code is:
import cv2
import numpy as np
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
verdeBajo = np.array([40, 170, 170],np.uint8)
verdeAlto = np.array([85, 255, 255],np.uint8)
redBajo1 = np.array([0,170,170],np.uint8)
redAlto1 = np.array([10,255,255],np.uint8)
redBajo2 = np.array([173,170,170],np.uint8)
redAlto2 = np.array([179,255,255],np.uint8)
semaforoClassif = cv2.CascadeClassifier('cascade.xml')
while True:
ret,frame = cap.read()
if ret==True:
frameHSV = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
toy = semaforoClassif.detectMultiScale(frameHSV,
scaleFactor = 5,
minNeighbors = 400,
minSize=(70,78))
for (x,y,w,h) in toy:
cv2.rectangle(frame, (x,y),(x+w,y+h),(255,0,0),2)
cv2.putText(frame,'Semaforo',(x,y-10),2,0.7,(255,0,0),2,cv2.LINE_AA)
rectangulo=cv2.rectangle(frame, (x,y),(x+w,y+h),(255,0,0),2)
frameHSV2 = cv2.cvtColor(rectangulo,cv2.COLOR_BGR2HSV)
maskRed1 = cv2.inRange(frameHSV2,redBajo1,redAlto1)
maskRed2 = cv2.inRange(frameHSV2,redBajo2,redAlto2)
mask = cv2.inRange(frameHSV2,verdeBajo,verdeAlto)
contornos,hierachy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contornosr1,hierarchy2=cv2.findContours(maskRed1,cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contornosr2,hierarchy3=cv2.findContours(maskRed2,cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(rectangulo, contornosr1, -1, (0,0,255), 0)
cv2.drawContours(rectangulo, contornosr2, -1, (0,0,255), 0)
cv2.drawContours(rectangulo, contornos, -1, (0,255,0), 0)
cv2.imshow('maskGreen',mask)
cv2.imshow('frame',frame)
cv2.imshow('maskRed1', maskRed1)
cv2.imshow('maskRed2', maskRed2)
if cv2.waitKey(1) & 0xFF == ord('c'):
break
cap.release()
cv2.destroyAllWindows()