【发布时间】:2018-08-13 17:37:55
【问题描述】:
在 Google colaboratory 中,当尝试使用 opencv haar-cascade 分类器并加载分类器数据时,库使用路径来确定分类器数据的位置。
如何在协作笔记本中指定此路径,因为通常文件是从谷歌驱动器加载或上传的?如果opencv加载图片,这也能做到?
Colab 笔记本的外观如下:
# install opencv
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
# load the cascades. I'd like to know how to properly set the below path if using google drive for uploading this data. Or if there is another recommended approach
cascades_path = '/usr/share/opencv/haarcascades/'
face_cascade = cv2.CascadeClassifier(cascades_path + 'haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(cascades_path + 'haarcascade_eye.xml')
# load an image. How should this path be specified with opencv in google colaboratory?
img = cv2.imread('images/image2.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_detections = face_cascade.detectMultiScale(gray, 1.3, 5)
【问题讨论】:
-
你得到答案了吗?
标签: python opencv google-colaboratory