【发布时间】:2021-04-10 21:25:00
【问题描述】:
第一次发帖。
我目前正在尝试在 M1 macbook air 上使用虚拟工作室在 python 中使用 opencv2,但由于某种原因我不能使用 detectMultiScale 函数?我已完全卸载所有内容并重新安装所有内容均无济于事。 error: (-215) !empty() in function detectMultiScale
例如: grayscaled_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_coordinates = train_face_data.detectMultiScale(grayscaled_img)
了解我
face_coordinates = trained_face_data.detectMultiScale(grayscaled_img)
cv2.error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-39p1qqfs/opencv/modules/objdetect/src/cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'
另外,我对使用 python 完全陌生,所以我有一个快速的问题是我是否需要创建一个虚拟环境,激活它,然后在那里 pip 下载 opencv2?我尝试将 cv2 下载到我的 python 文件的终端中,但我无法在那里导入 cv2。我在想可能是因为文件路径不同?但我不知道如何将 pip 安装程序用于某个文件路径。我只能在 venv 中安装 cv2 后才能导入 cv2。
请指教,谢谢!
在问这个问题之前我已经试过了:
import cv2
#trained face data import
trained_face_data = cv2.CascadeClassifier('frontfacedetector.xml')
#import my face
img = cv2.imread('Aaron_Prof_Pic.jpg')
#change to grayscale
grayscaled_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#detecting faces
face_coordinates = trained_face_data.detectMultiScale(grayscaled_img)
cv2.imshow('why isnt this working', grayscaled_img)
cv2.waitKey()
print("Code completed")
【问题讨论】: