Spaces:
Build error
Build error
has12zen
commited on
Commit
·
5408b2a
1
Parent(s):
c379def
Test
Browse files
utils.py
CHANGED
@@ -5,27 +5,27 @@ import multiprocessing
|
|
5 |
from PIL import Image
|
6 |
import numpy as np
|
7 |
import itertools
|
8 |
-
import logging
|
9 |
import math
|
10 |
import cv2
|
11 |
import os
|
12 |
|
13 |
|
14 |
-
logging.basicConfig(filename=f'{os.getcwd()}/frame_processing.log', level=logging.INFO)
|
15 |
-
logging.info('Starting frame processing')
|
16 |
fps = 0
|
17 |
def read_file(name):
|
18 |
global fps
|
19 |
cap = cv2.VideoCapture(name)
|
20 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
21 |
if not cap.isOpened():
|
22 |
-
logging.error("Cannot open Video")
|
23 |
exit()
|
24 |
frames = []
|
25 |
while True:
|
26 |
ret,frame = cap.read()
|
27 |
if not ret:
|
28 |
-
logging.info("Can't receive frame (stream end?). Exiting ...")
|
29 |
break
|
30 |
frames.append(frame)
|
31 |
|
@@ -95,7 +95,7 @@ q = 3
|
|
95 |
t = 2
|
96 |
def process_video(frames_with_index):
|
97 |
num_processes = multiprocessing.cpu_count()
|
98 |
-
logging.info(f"Using {num_processes} processes")
|
99 |
pool = multiprocessing.Pool(num_processes)
|
100 |
# process the frames in parallel
|
101 |
processed_frames = pool.map(process_frame, frames_with_index)
|
@@ -133,13 +133,13 @@ def each_frame(frame_and_index,processed_frames):
|
|
133 |
f3 = processed_frames[index+3][i,j]
|
134 |
k = (frame[i,j], f1, f2, f3)
|
135 |
freq_dict3[k]=freq_dict3.get(k,0)+1
|
136 |
-
logging.info(f"hist made for frame {index}")
|
137 |
return (freq_dict,freq_dict2,freq_dict3)
|
138 |
|
139 |
def extract_video(processed_frame_with_index):
|
140 |
processed_frames = [frame for frame, index in processed_frame_with_index]
|
141 |
num_processes = multiprocessing.cpu_count()
|
142 |
-
logging.info(f"Using2 {num_processes} processes")
|
143 |
pool = multiprocessing.Pool(num_processes)
|
144 |
# process the frames in parallel
|
145 |
freq_dict_list = pool.starmap(each_frame, zip(processed_frame_with_index,itertools.repeat(processed_frames)))
|
|
|
5 |
from PIL import Image
|
6 |
import numpy as np
|
7 |
import itertools
|
8 |
+
# import logging
|
9 |
import math
|
10 |
import cv2
|
11 |
import os
|
12 |
|
13 |
|
14 |
+
# logging.basicConfig(filename=f'{os.getcwd()}/frame_processing.log', level=logging.INFO)
|
15 |
+
# logging.info('Starting frame processing')
|
16 |
fps = 0
|
17 |
def read_file(name):
|
18 |
global fps
|
19 |
cap = cv2.VideoCapture(name)
|
20 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
21 |
if not cap.isOpened():
|
22 |
+
# logging.error("Cannot open Video")
|
23 |
exit()
|
24 |
frames = []
|
25 |
while True:
|
26 |
ret,frame = cap.read()
|
27 |
if not ret:
|
28 |
+
# logging.info("Can't receive frame (stream end?). Exiting ...")
|
29 |
break
|
30 |
frames.append(frame)
|
31 |
|
|
|
95 |
t = 2
|
96 |
def process_video(frames_with_index):
|
97 |
num_processes = multiprocessing.cpu_count()
|
98 |
+
# logging.info(f"Using {num_processes} processes")
|
99 |
pool = multiprocessing.Pool(num_processes)
|
100 |
# process the frames in parallel
|
101 |
processed_frames = pool.map(process_frame, frames_with_index)
|
|
|
133 |
f3 = processed_frames[index+3][i,j]
|
134 |
k = (frame[i,j], f1, f2, f3)
|
135 |
freq_dict3[k]=freq_dict3.get(k,0)+1
|
136 |
+
# logging.info(f"hist made for frame {index}")
|
137 |
return (freq_dict,freq_dict2,freq_dict3)
|
138 |
|
139 |
def extract_video(processed_frame_with_index):
|
140 |
processed_frames = [frame for frame, index in processed_frame_with_index]
|
141 |
num_processes = multiprocessing.cpu_count()
|
142 |
+
# logging.info(f"Using2 {num_processes} processes")
|
143 |
pool = multiprocessing.Pool(num_processes)
|
144 |
# process the frames in parallel
|
145 |
freq_dict_list = pool.starmap(each_frame, zip(processed_frame_with_index,itertools.repeat(processed_frames)))
|