Hi im trying to detect some license platings with a Classifier from cv2. (on Windows)
I installed open-cv via pip install in a venv
(path: C:\Users\ramif\Desktop\StraßenverkehrProjekt\venv\Lib\site-packages\cv2)
import cv2
import matplotlib.pyplot as plt
x = cv2.imread("P1010003.jpg")
gray = cv2.cvtColor(x, cv2.COLOR_BGR2GRAY)
classifier = cv2.CascadeClassifier('venv\Lib\site-packages\cv2\data\haarcascade_russian_plate_number.xml')
platings = classifier.detectMultiScale(gray, minNeighbors = 10)
c = x.copy()
for plating in platings:
x, y, w, h = plating
cv2.rectangle(c, (x, y), (x+w, y+h), (55, 175, 212), 10)
z = cv2.cvtColor(c, cv2.COLOR_BGR2RGB)
print(plating)
plt.imshow(z)
plt.show()
This Code works fine, but when i try to read multiple images with a for-loop, it doesnt work anymore. How can I read multiple images with the detectMultiscale function?
Here an example Code how i tried to read it: (Failed Code)
import os
import cv2
import matplotlib.pyplot as plt
file = os.path.join(os.path.dirname(__file__), "Bilder")
os.chdir(file)
img = []
for i in os.listdir(file):
x = cv2.imread(i)
img.append(x)
break
for j in img:
gray = cv2.cvtColor(j, cv2.COLOR_BGR2GRAY)
classifier = cv2.CascadeClassifier('venv\Lib\site-packages\cv2\data\haarcascade_russian_plate_number.xml')
platings = classifier.detectMultiScale(gray)
print(platings)