Reputation: 41
I just started learning AI using OpenCV and am creating an AI to detect pedestrians. I ran into the problem of not being able to open and read the "hogcascade_pedestrain.xml" file.
Things I have tried:
However, it would still give the same error:
[ERROR:[email protected]] global persistence.cpp:505 cv::FileStorage::Impl::open Can't open file: 'C:\Python\Python311\Lib\site-packages\cv2\data\hogcascade_pedestrain.xml' in read mode
Here is my code
import cv2
# Load the pre-trained classifier
pedestrain_classifier = cv2.CascadeClassifier(cv2.data.haarcascades + "hogcascade_pedestrains.xml")
frame = cv2.imread("pedestrain.jpg")
# Convert frame to grayscale
grayscaled_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect pedestrain
pedestrain_coordinates = pedestrain_classifier.detectMultiScale(grayscaled_img)
# Draw rectangle
for (x, y, w, h) in pedestrain_coordinates:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Dispay frame
cv2.imshow("Clever road detector", frame)
# Wait
cv2.waitKey()
Upvotes: 1
Views: 16018
Reputation: 41
OpenCV versions 3.0 and later DO NOT support hogcascades anymore.
See here for original post: https://stackoverflow.com/a/72701276/20926636
Changed the hogcascade to a haarcascade and it worked fine opening the file and running the rest of the code.
Upvotes: 1