opencv中文http://www.woshicver.com/http://www.woshicver.com/
官网https://opencv.org/https://opencv.org/
安装好Python. pycharm链接https://www.jetbrains.com/zh-cn/pycharm/https://www.jetbrains.com/zh-cn/pycharm/
pip install opencv-python -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com/pypi/simple(1)代码
import cv2 import sys import time def zcx_jr(): cameraCapture = cv2.VideoCapture('/Users/chenyutong/documents/pym1/未命名文件夹/video.mp4')#视频地址 # cv2级联分类器CascadeClassifier,xml文件为训练数据 face_cascade = cv2.CascadeClassifier('/Users/chenyutong/documents/资源库/opencv/haarcascade_frontalface_default.xml') success, frame = cameraCapture.read() while success and cv2.waitKey(1) == -1: ret, img = cameraCapture.read() faces = face_cascade.detectMultiScale(img, 1.3, 5) for (x, y, w, h) in faces: img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.namedWindow('camera', 0) cv2.resizeWindow('camera', 840, 480) cv2.imshow('camera', img) success, frame = cameraCapture.read() cameraCapture.release() cv2.destroyAllWindows() time.sleep(20) sys.exit() if __name__ == '__main__': zcx_jr()(2)结果展示
以上就是本文所有内容,希望能帮到大家
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)