fixed color conversion
Browse files
app.py
CHANGED
@@ -29,8 +29,6 @@ import boto3
|
|
29 |
import os
|
30 |
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
|
31 |
os.environ['OMP_NUM_THREADS'] = '4'
|
32 |
-
os.environ['AWS_ACCESS_KEY_ID'] = 'AKIA3JAMX4K53MFDKMGJ'
|
33 |
-
os.environ['AWS_SECRET_ACCESS_KEY'] = 'lHf9xIwdgO3eXrE9a4KL+BTJ7af2cgZJYRRxw4NI'
|
34 |
|
35 |
app_version = 'dsdg_vid_2'
|
36 |
|
@@ -97,7 +95,7 @@ def extract_face(img):
|
|
97 |
face = None
|
98 |
if img is None:
|
99 |
return face
|
100 |
-
grey = cv.cvtColor(img, cv.
|
101 |
faces = faceClassifier.detectMultiScale(
|
102 |
grey, scaleFactor=1.1, minNeighbors=4)
|
103 |
if len(faces):
|
@@ -161,14 +159,14 @@ def prepare_data_dsdg(images, boxes, depths):
|
|
161 |
for i, (image, bbox, depth_img) in enumerate(
|
162 |
zip(images, boxes, depths)):
|
163 |
x, y, x2, y2 = bbox
|
164 |
-
depth_img = cv.cvtColor(depth_img, cv.
|
165 |
image = image[y:y2, x:x2]
|
166 |
depth_img = depth_img[y:y2, x:x2]
|
167 |
|
168 |
image_x[i, :, :, :] = cv.resize(image, (256, 256))
|
169 |
# transform to binary mask --> threshold = 0
|
170 |
depth_x[i, :, :] = cv.resize(depth_img, (32, 32))
|
171 |
-
image_x = image_x.transpose((0, 3, 1, 2))
|
172 |
image_x = transform(image_x)
|
173 |
image_x = torch.from_numpy(image_x.astype(float)).float()
|
174 |
depth_x = torch.from_numpy(depth_x.astype(float)).float()
|
@@ -235,7 +233,6 @@ def process_video(vid_path, dsdg_thresh):
|
|
235 |
# Process only every 5th frame
|
236 |
if frame_counter % 5 == 0:
|
237 |
# Run inference on the current frame
|
238 |
-
frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
|
239 |
img, bbox, depth_img = analyze_face(frame)
|
240 |
if bbox and (depth_img is not None):
|
241 |
inference_images.append(img)
|
@@ -254,7 +251,7 @@ def process_video(vid_path, dsdg_thresh):
|
|
254 |
w = x2 - x
|
255 |
h = y2 - y
|
256 |
frame_cls = 'Real' if score >= dsdg_thresh else 'Spoof'
|
257 |
-
color_dsdg = (0, 255, 0) if frame_cls == 'Real' else (
|
258 |
text = f'{cls_dsdg} {w}*{h}'
|
259 |
cv.rectangle(img, (x, y), (x2, y2), color_dsdg, 2)
|
260 |
cv.putText(img, text, (x, y2 + 30), cv.FONT_HERSHEY_COMPLEX, 1, color_dsdg)
|
@@ -262,8 +259,7 @@ def process_video(vid_path, dsdg_thresh):
|
|
262 |
out_dsdg = cv.VideoWriter(output_vid_path, fourcc, 6.0, (input_width, input_height))
|
263 |
for img in all_frames:
|
264 |
# Write the DSDG frame to the output video
|
265 |
-
|
266 |
-
out_dsdg.write(img_dsdg)
|
267 |
out_dsdg.release()
|
268 |
text_dsdg = f'Label: {cls_dsdg}, average real confidence: {res_dsdg}\nFrames used: {len(scores)}\nConfidences: {scores}'
|
269 |
return vid_path, {'Not supported right now': 0}, -1, output_vid_path, text_dsdg, res_dsdg
|
|
|
29 |
import os
|
30 |
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
|
31 |
os.environ['OMP_NUM_THREADS'] = '4'
|
|
|
|
|
32 |
|
33 |
app_version = 'dsdg_vid_2'
|
34 |
|
|
|
95 |
face = None
|
96 |
if img is None:
|
97 |
return face
|
98 |
+
grey = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
|
99 |
faces = faceClassifier.detectMultiScale(
|
100 |
grey, scaleFactor=1.1, minNeighbors=4)
|
101 |
if len(faces):
|
|
|
159 |
for i, (image, bbox, depth_img) in enumerate(
|
160 |
zip(images, boxes, depths)):
|
161 |
x, y, x2, y2 = bbox
|
162 |
+
depth_img = cv.cvtColor(depth_img, cv.COLOR_BGR2GRAY)
|
163 |
image = image[y:y2, x:x2]
|
164 |
depth_img = depth_img[y:y2, x:x2]
|
165 |
|
166 |
image_x[i, :, :, :] = cv.resize(image, (256, 256))
|
167 |
# transform to binary mask --> threshold = 0
|
168 |
depth_x[i, :, :] = cv.resize(depth_img, (32, 32))
|
169 |
+
image_x = image_x[:, :, :, ::-1].transpose((0, 3, 1, 2))
|
170 |
image_x = transform(image_x)
|
171 |
image_x = torch.from_numpy(image_x.astype(float)).float()
|
172 |
depth_x = torch.from_numpy(depth_x.astype(float)).float()
|
|
|
233 |
# Process only every 5th frame
|
234 |
if frame_counter % 5 == 0:
|
235 |
# Run inference on the current frame
|
|
|
236 |
img, bbox, depth_img = analyze_face(frame)
|
237 |
if bbox and (depth_img is not None):
|
238 |
inference_images.append(img)
|
|
|
251 |
w = x2 - x
|
252 |
h = y2 - y
|
253 |
frame_cls = 'Real' if score >= dsdg_thresh else 'Spoof'
|
254 |
+
color_dsdg = (0, 255, 0) if frame_cls == 'Real' else (0, 0, 255)
|
255 |
text = f'{cls_dsdg} {w}*{h}'
|
256 |
cv.rectangle(img, (x, y), (x2, y2), color_dsdg, 2)
|
257 |
cv.putText(img, text, (x, y2 + 30), cv.FONT_HERSHEY_COMPLEX, 1, color_dsdg)
|
|
|
259 |
out_dsdg = cv.VideoWriter(output_vid_path, fourcc, 6.0, (input_width, input_height))
|
260 |
for img in all_frames:
|
261 |
# Write the DSDG frame to the output video
|
262 |
+
out_dsdg.write(img)
|
|
|
263 |
out_dsdg.release()
|
264 |
text_dsdg = f'Label: {cls_dsdg}, average real confidence: {res_dsdg}\nFrames used: {len(scores)}\nConfidences: {scores}'
|
265 |
return vid_path, {'Not supported right now': 0}, -1, output_vid_path, text_dsdg, res_dsdg
|