This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
testCrop.py
83 lines (57 loc) · 2.2 KB
/
testCrop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# import cv2
# import sys
# #imagePath = sys.argv[1]
# cascPath = "face_detector.xml"
# faceCascade = cv2.CascadeClassifier(cascPath)
# #can also provide a video file here and python would read and capture using ffmpeg
# #defauly webcam
# video_capture = cv2.VideoCapture("TestVideo.mp4")
# while (video_capture.isOpened()):
# # Capture frame-by-frame ret-is for when we run out of frames but since it's webcam we can record forever
# ret, frame = video_capture.read()
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# faces = faceCascade.detectMultiScale(
# gray,
# scaleFactor=1.1,
# minNeighbors=5,
# minSize=(30, 30),
# #flags=cv2.cv.CV_HAAR_SCALE_IMAGE
# )
# # Draw a rectangle around the faces
# # for (x, y, w, h) in faces:
# # cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 4)
# for f in faces:
# x, y, w, h = [ v for v in f ]
# cv2.rectangle(image_copy, (x,y), (x+w, y+h), (255,0,0), 3)
# # Define the region of interest in the image
# face_crop.append(gray[y:y+h, x:x+w])
# for face in face_crop:
# cv2.imshow('face',face)
# cv2.waitKey(0)
# face_crop = gray[y:y+h, x:x+w]
# # Display the image with the bounding boxes
# fig = plt.figure(figsize = (9,9))
# axl = fig.add_subplot(111)
# axl.set_xticks([])
# axl.set_yticks([])
# ax1.set_title("Obamas with Face Detection")
# axl.imshow(image_copy)
# # Display the face crops
# fig = plt.figure(figsize = (9,9))
# axl = fig.add_subplot(111)
# axl.set_xticks([])
# axl.set_yticks([])
# axl.set_title("Obamas Face Crops")
# axl.imshow(face_crop)
# # Display the resulting frame
# cv2.imshow('Video', frame)
# cv2.imwrite('Video.png', frame)
# print('Face was detected & snapshot saved sucessfully')
# #searching for frame - q key exists the script
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
# # cv2.imwrite("face_detected.mp4", frame)
# # print('Face was detected sucessfuly saved')
# # When everything is done, release the capture
# video_capture.release()
# cv2.destroyAllWindows()