Mitul Mohammad Abdullah Al Mukit commited on
Commit
1c82367
1 Parent(s): 53bab76

attempt to fix resize bug

Browse files
Files changed (1) hide show
  1. demo.py +13 -6
demo.py CHANGED
@@ -6,6 +6,7 @@ import imageSegmentation
6
 
7
  from mediapipe.tasks.python import vision
8
  import Visualization_utilities as vis
 
9
 
10
  # Get a reference to webcam #0 (the default one)
11
  # video_capture = cv2.VideoCapture(0)
@@ -79,10 +80,16 @@ def process_frame(frame, process_this_frame, face_locations, faces, face_names,
79
  if process_this_frame:
80
  face_names = []
81
  # Resize frame of video to 1/4 size for faster face recognition processing
82
- small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
 
 
 
 
 
 
83
 
84
  # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
85
- rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
86
 
87
  # Find all the faces and face encodings in the current frame of video
88
  face_locations = face_recognition.face_locations(rgb_small_frame)
@@ -135,10 +142,10 @@ def process_frame(frame, process_this_frame, face_locations, faces, face_names,
135
 
136
  for (top, right, bottom, left), name in zip(face_locations, face_names):
137
  # Scale back up face locations since the frame we detected in was scaled to 1/4 size
138
- top *= 4
139
- right *= 4
140
- bottom *= 4
141
- left *= 4
142
 
143
  # Draw a box around the face
144
  cv2.rectangle(frame, (left, top), (right, bottom), (65, 181, 41), 4)
 
6
 
7
  from mediapipe.tasks.python import vision
8
  import Visualization_utilities as vis
9
+ import time
10
 
11
  # Get a reference to webcam #0 (the default one)
12
  # video_capture = cv2.VideoCapture(0)
 
80
  if process_this_frame:
81
  face_names = []
82
  # Resize frame of video to 1/4 size for faster face recognition processing
83
+ # if frame != None:
84
+ # print(f'frame: {len(frame)}')
85
+ # try:
86
+ # small_frame = cv2.imread(image_dir)
87
+ # small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
88
+ # else:
89
+ # print('fram has nth')
90
 
91
  # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
92
+ rgb_small_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # edited
93
 
94
  # Find all the faces and face encodings in the current frame of video
95
  face_locations = face_recognition.face_locations(rgb_small_frame)
 
142
 
143
  for (top, right, bottom, left), name in zip(face_locations, face_names):
144
  # Scale back up face locations since the frame we detected in was scaled to 1/4 size
145
+ # top *= 4
146
+ # right *= 4
147
+ # bottom *= 4
148
+ # left *= 4
149
 
150
  # Draw a box around the face
151
  cv2.rectangle(frame, (left, top), (right, bottom), (65, 181, 41), 4)