Spaces:
Runtime error
Runtime error
Commit
·
54696a3
1
Parent(s):
878be3f
Update app
Browse files- app.py +3 -3
- config.py +1 -1
- frame_differencing.py +3 -4
- requirements.txt +1 -0
- utils.py +13 -9
- video_2_slides.py +2 -2
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
import glob
|
4 |
import validators
|
|
|
5 |
from config import *
|
6 |
from download_video import download_video
|
7 |
from bg_modeling import capture_slides_bg_modeling
|
@@ -48,11 +48,11 @@ def process(
|
|
48 |
output_dir_path, hash_size, hash_func, hash_queue_len, diff_threshold
|
49 |
)
|
50 |
|
51 |
-
pdf_path = convert_slides_to_pdf(
|
52 |
|
53 |
# Remove unneccessary files
|
54 |
os.remove(video_path)
|
55 |
-
for image_path in
|
56 |
os.remove(image_path)
|
57 |
return pdf_path
|
58 |
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
import validators
|
4 |
+
from imutils import paths
|
5 |
from config import *
|
6 |
from download_video import download_video
|
7 |
from bg_modeling import capture_slides_bg_modeling
|
|
|
48 |
output_dir_path, hash_size, hash_func, hash_queue_len, diff_threshold
|
49 |
)
|
50 |
|
51 |
+
pdf_path = convert_slides_to_pdf(output_dir_path)
|
52 |
|
53 |
# Remove unneccessary files
|
54 |
os.remove(video_path)
|
55 |
+
for image_path in paths.list_images(output_dir_path):
|
56 |
os.remove(image_path)
|
57 |
return pdf_path
|
58 |
|
config.py
CHANGED
@@ -4,7 +4,7 @@ import imagehash
|
|
4 |
|
5 |
DOWNLOAD_DIR = "downloads"
|
6 |
|
7 |
-
FRAME_BUFFER_HISTORY =
|
8 |
DEC_THRESH = (
|
9 |
0.75 # Threshold value, above which it is marked foreground, else background.
|
10 |
)
|
|
|
4 |
|
5 |
DOWNLOAD_DIR = "downloads"
|
6 |
|
7 |
+
FRAME_BUFFER_HISTORY = 10 # Length of the frame buffer history to model background.
|
8 |
DEC_THRESH = (
|
9 |
0.75 # Threshold value, above which it is marked foreground, else background.
|
10 |
)
|
frame_differencing.py
CHANGED
@@ -40,7 +40,7 @@ def capture_slides_frame_diff(
|
|
40 |
|
41 |
screenshots_count += 1
|
42 |
|
43 |
-
filename = f"{screenshots_count:03}.
|
44 |
out_file_path = os.path.join(output_dir_path, filename)
|
45 |
print(f"Saving file at: {out_file_path}")
|
46 |
|
@@ -68,7 +68,6 @@ def capture_slides_frame_diff(
|
|
68 |
|
69 |
if p_non_zero >= MIN_PERCENT_THRESH and not capture_frame:
|
70 |
capture_frame = True
|
71 |
-
|
72 |
elif capture_frame:
|
73 |
frame_elapsed += 1
|
74 |
|
@@ -78,11 +77,11 @@ def capture_slides_frame_diff(
|
|
78 |
|
79 |
screenshots_count += 1
|
80 |
|
81 |
-
filename = f"{screenshots_count:03}.
|
82 |
out_file_path = os.path.join(output_dir_path, filename)
|
83 |
print(f"Saving file at: {out_file_path}")
|
84 |
|
85 |
-
cv2.imwrite(out_file_path, frame)
|
86 |
|
87 |
prev_frame = curr_frame
|
88 |
|
|
|
40 |
|
41 |
screenshots_count += 1
|
42 |
|
43 |
+
filename = f"{screenshots_count:03}.jpg"
|
44 |
out_file_path = os.path.join(output_dir_path, filename)
|
45 |
print(f"Saving file at: {out_file_path}")
|
46 |
|
|
|
68 |
|
69 |
if p_non_zero >= MIN_PERCENT_THRESH and not capture_frame:
|
70 |
capture_frame = True
|
|
|
71 |
elif capture_frame:
|
72 |
frame_elapsed += 1
|
73 |
|
|
|
77 |
|
78 |
screenshots_count += 1
|
79 |
|
80 |
+
filename = f"{screenshots_count:03}.jpg"
|
81 |
out_file_path = os.path.join(output_dir_path, filename)
|
82 |
print(f"Saving file at: {out_file_path}")
|
83 |
|
84 |
+
cv2.imwrite(out_file_path, frame, [cv2.IMWRITE_JPEG_QUALITY, 75])
|
85 |
|
86 |
prev_frame = curr_frame
|
87 |
|
requirements.txt
CHANGED
@@ -4,6 +4,7 @@ Pillow
|
|
4 |
scipy
|
5 |
six
|
6 |
ImageHash
|
|
|
7 |
img2pdf
|
8 |
pytube
|
9 |
validators
|
|
|
4 |
scipy
|
5 |
six
|
6 |
ImageHash
|
7 |
+
imutils
|
8 |
img2pdf
|
9 |
pytube
|
10 |
validators
|
utils.py
CHANGED
@@ -3,7 +3,7 @@ import re
|
|
3 |
import cv2
|
4 |
import shutil
|
5 |
import img2pdf
|
6 |
-
import
|
7 |
|
8 |
# PIL can also be used to convert the image set into PDFs.
|
9 |
# However, using PIL requires opening each of the images in the set.
|
@@ -46,17 +46,21 @@ def create_output_directory(video_path, output_path, type_bgsub):
|
|
46 |
return output_dir_path
|
47 |
|
48 |
|
49 |
-
def convert_slides_to_pdf(
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
print("Output PDF Path:", output_pdf_path)
|
54 |
print("Converting captured slide images to PDF...")
|
55 |
-
|
56 |
-
|
57 |
-
f.write(img2pdf.convert(sorted(glob.glob(f"{output_path}/*.jpg"))))
|
58 |
|
59 |
print("PDF Created!")
|
60 |
print("***" * 10, "\n")
|
61 |
|
62 |
-
return
|
|
|
3 |
import cv2
|
4 |
import shutil
|
5 |
import img2pdf
|
6 |
+
from imutils import paths
|
7 |
|
8 |
# PIL can also be used to convert the image set into PDFs.
|
9 |
# However, using PIL requires opening each of the images in the set.
|
|
|
46 |
return output_dir_path
|
47 |
|
48 |
|
49 |
+
def convert_slides_to_pdf(img_dir, output_path=None):
|
50 |
+
if not os.path.isdir(img_dir):
|
51 |
+
print("The image directory doesn't exist!")
|
52 |
+
return
|
53 |
+
|
54 |
+
if output_path == None:
|
55 |
+
pdf_file_name = os.path.basename(img_dir) + ".pdf"
|
56 |
+
output_path = os.path.join(img_dir, pdf_file_name)
|
57 |
+
print("Output PDF Path:", output_path)
|
58 |
|
|
|
59 |
print("Converting captured slide images to PDF...")
|
60 |
+
with open(output_path, "wb") as f:
|
61 |
+
f.write(img2pdf.convert(sorted(paths.list_images(img_dir))))
|
|
|
62 |
|
63 |
print("PDF Created!")
|
64 |
print("***" * 10, "\n")
|
65 |
|
66 |
+
return output_path
|
video_2_slides.py
CHANGED
@@ -81,7 +81,7 @@ if __name__ == "__main__":
|
|
81 |
)
|
82 |
queue_len = HASH_BUFFER_HISTORY
|
83 |
|
84 |
-
video_path = args.
|
85 |
output_dir_path = args.out_dir
|
86 |
type_bg_sub = args.type
|
87 |
temp_file = False
|
@@ -128,7 +128,7 @@ if __name__ == "__main__":
|
|
128 |
)
|
129 |
|
130 |
if args.convert_to_pdf:
|
131 |
-
convert_slides_to_pdf(
|
132 |
|
133 |
# if temp_file:
|
134 |
# os.remove(video_path)
|
|
|
81 |
)
|
82 |
queue_len = HASH_BUFFER_HISTORY
|
83 |
|
84 |
+
video_path = args.video_path
|
85 |
output_dir_path = args.out_dir
|
86 |
type_bg_sub = args.type
|
87 |
temp_file = False
|
|
|
128 |
)
|
129 |
|
130 |
if args.convert_to_pdf:
|
131 |
+
convert_slides_to_pdf(output_dir_path)
|
132 |
|
133 |
# if temp_file:
|
134 |
# os.remove(video_path)
|