• 基于Opencv自有模型识别人脸与人眼


    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    import cv2
    face_cascade = cv2.CascadeClassifier("D:/Open-cv/opencv/build/etc/haarcascades/haarcascade_frontalface_default.xml")
    eye_cascade = cv2.CascadeClassifier("D:/Open-cv/opencv/build/etc/haarcascades/haarcascade_eye.xml")
    cap = cv2.VideoCapture(1)
    while True:
        ret, frame = cap.read()
        i = frame
        # print i.shape
        gray = cv2.cvtColor(i, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray, 1.3, 5)
        
        l = len(faces)
        print (l)
        for (x, y, w, h) in faces:
            cv2.rectangle(i, (x, y), (x + w, y + h), (255, 0, 0), 2)
            # cv2.putText(i,'face',(w/2+x,y-h/5),cv2.FONT_HERSHEY_PLAIN,2.0,(255,255,255),2,1)
            roi_gray = gray[y:y + h, x:x + w]
            roi_color = i[y:y + h, x:x + w]
            eyes = eye_cascade.detectMultiScale(roi_gray)
            for (ex, ey, ew, eh) in eyes:
                cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
                cv2.putText(i, "face count", (20, 20), cv2.FONT_HERSHEY_PLAIN, 2.0, (255, 255, 255), 2, 1)
                cv2.putText(i, str(l), (230, 20), cv2.FONT_HERSHEY_PLAIN, 2.0, (255, 255, 255), 2, 1)
        cv2.imshow("rstp", i)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            exit(0)
    

  • 相关阅读:
    Python笔记220151023
    B/S和C/S【转载Jane的博客 http://blog.sina.com.cn/liaojane】
    Java Queue
    Java 使用 .this与.new
    Java多态继承与清理
    Java 匿名类
    Java 内部类2
    java 中的多重继承
    Java 内部类
    Java 异常(自定义异常)
  • 原文地址:https://www.cnblogs.com/gmhappy/p/9472423.html
Copyright © 2020-2023  润新知