Created
February 13, 2019 19:17
-
-
Save henripal/fab38551ac6077c6202ab44364a7ab05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink") | |
# Create the haar cascade | |
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") | |
cv2.namedWindow('demo', cv2.WINDOW_AUTOSIZE) | |
while(True): | |
# Capture frame-by-frame | |
ret, frame = cap.read() | |
# Our operations on the frame come here | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
# gray = cv2.resize(gray, (640, 360)) | |
# Detect faces in the image | |
faces = faceCascade.detectMultiScale( | |
gray,scaleFactor=1.1, minNeighbors=5, minSize = (30,30) | |
) | |
print("Found {0} faces!".format(len(faces))) | |
# Draw a rectangle around the faces | |
for (x, y, w, h) in faces: | |
cv2.rectangle(gray, (x, y), (x+w, y+h), (255, 0, 0), 2) | |
# Display the resulting frame | |
cv2.imshow('demo', gray) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
# When everything done, release the capture | |
cap.release() | |
cv2.destroyAllWindows() | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment