学习笔记:opencv读取摄像头并进行人脸识别
# -*- coding: UTF-8 -*-
import cv2
#cap = cv2.VideoCapture("2.mp4")
import sys,getopt
cap = cv2.VideoCapture("rtsp://admin:1234qwer@192.168.2.11/Streaming/Channels/101")
print (cap.isOpened())
fps_mp4=cap.get(cv2.CAP_PROP_FPS)
print(fps_mp4)
size_mp4 = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print(size_mp4)
success,frame = cap.read()
#print(frame.size)
face_cascade = cv2.CascadeClassifier('./cascades/haarcascade_frontalface_default.xml')
show_switch = 0
i = 100
fps = 30
size = (1920,1080)
while cap.isOpened():
success,frame1 = cap.read()
frame = frame1[200:800,500:1500]
i = i+1
gray = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
if (i > 3):
faces = face_cascade.detectMultiScale(frame,1.3,5)
i = 0
print 'cascade-'
print len(faces)
show_switch = 1
#img = cv2.rectangle(frame,(80,80),(160,160),(0,255,0),2)
for(x,y,w,h) in faces:
#img = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
img = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
if( show_switch == 1):
print "detect-------------------------------","x = ",x,"y = ",y,"w=",w,"h=",h
show_switch = 0
cv2.imshow("frame",frame)
# videoWriter.write(frame)
cv2.waitKey(1)
- 点赞
- 收藏
- 关注作者
评论(0)