Closed akhtarusafzai closed 5 years ago
hey maybe there is some error in installing opencv what is why you are getting cv2.cv2 maybe you have installed multiple times .try removing the current opencv from your environment and install it using conda as installing it through conda is much easier compared to installing in through pip.
Did your cv2 file exist?
I have the same issue . Any solution yet ?
1) use pip uninstall opencv-python 2)use pip install opencv-contrib-python 3)Update attributes "Python -m pip install opencv-contrib-python"
just use conda install opencv,-contrib-python this should solve the issue for anyone on jupyter notebook with anaconda
Hello @codingforentrepreneurs , I am using the same code as of yours and when I run it it shows me the following
Here is the code `import cv2 import os import numpy as np from PIL import Image import pickle
BASE_DIR = os.path.dirname(os.path.abspath(file)) image_dir = os.path.join(BASE_DIR, "images")
face_cascade = cv2.CascadeClassifier('cascades/data/haarcascade_frontalface_alt2.xml') recognizer = cv2.face.LBPHFaceRecognizer_create()
current_id = 0 label_ids = {} y_labels =[] x_train = []
for root, dirs, files in os.walk(image_dir): for file in files: if file.endswith(".png") or file.endswith(".jpg"): path = os.path.join(root, file) label = os.path.basename(os.path.dirname(path)).replace(" ", "-"). lower()
print(label, path)
with open("labels.pickle", 'wb') as f: pickle.dump(label_ids, f)
recognizer.train(x_train, np.array(y_labels)) recognizer.save("trainner.yml")`