pull/1567/head
Piero Toffanin 2023-01-18 11:44:02 -05:00
rodzic 94d0fedc0d
commit 3296aa7a51
3 zmienionych plików z 19 dodań i 101 usunięć

Wyświetl plik

@ -5,22 +5,6 @@ import os
class Parameters:
input = None
output = None
start = None
end = None
output_resolution = None
blur_percentage = None
blur_threshold = None
distance_threshold = None
black_ratio_threshold = None
pixel_black_threshold = None
use_srt = None
timezone = None
frame_format = None
stats_file = None
limit = None
def __init__(self, args):
# "input" -> path to input video file(s), use ',' to separate multiple files")
@ -37,94 +21,29 @@ class Parameters:
# "frame-format" -> frame format (jpg, png, tiff, etc.)")
# "stats-file" -> Save statistics to csv file")
if (not self.ValidateParameters(args)):
print("Invalid parameters")
exit()
if not os.path.exists(args["output"]):
os.makedirs(args["output"])
self.input = args["input"].split(",")
self.output = args["output"]
self.start = args.get("start", 0)
self.end = args.get("end", None)
self.limit = args.get("limit", None)
self.blur_threshold = args.get("blur_threshold", None)
self.distance_threshold = args.get("distance_threshold", None)
self.black_ratio_threshold = args.get("black_ratio_threshold", None)
self.pixel_black_threshold = args.get("pixel_black_threshold", None)
self.use_srt = "use_srt" in args
self.frame_format = args.get("frame_format", "jpg")
# TODO: use max dimension
self.output_resolution = None
#self.output_resolution = tuple(map(int, args["output_resolution"].split("x"))) if args["output_resolution"] else None
self.start = args["start"] if args["start"] else 0
self.end = args["end"] if args["end"] else None
self.limit = args["limit"] if args["limit"] else None
self.blur_threshold = args["blur_threshold"] if args["blur_threshold"] else None
self.distance_threshold = args["distance_threshold"] if args["distance_threshold"] else None
self.black_ratio_threshold = args["black_ratio_threshold"] if args["black_ratio_threshold"] else None
self.pixel_black_threshold = args["pixel_black_threshold"] if args["pixel_black_threshold"] else None
self.use_srt = args["use_srt"]
self.frame_format = args["frame_format"]
self.output_resolution = tuple(map(int, args["output_resolution"].split("x"))) if args["output_resolution"] else None
self.stats_file = args["stats_file"] if args["stats_file"] else None
self.stats_file = args.get("stats_file", None)
# We will resize the image to this size before processing
self.internal_width = 800
self.internal_height = 600
# Validate parameters
def ValidateParameters(self, args):
# input can be a list of files comma separated, check for each file
files = args["input"].split(",")
for file in files:
if not os.path.exists(file):
print("Input file does not exist: " + file)
return False
if not os.path.exists(args["output"]):
os.makedirs(args["output"])
if args["start"] and args["start"] < 0:
print("Start frame index must be greater than 0")
return False
if args["limit"] and args["limit"] < 0:
print("Limit must be greater than 0")
return False
if args["end"]:
if args["end"] < 0:
print("End frame index must be greater than 0")
return False
if args["start"] is not None and args["end"] < args["start"]:
print("End frame index must be greater than start frame index")
return False
if args["blur_threshold"] and args["blur_threshold"] < 0:
print("Blur threshold must be greater than 0")
return False
if args["distance_threshold"] and args["distance_threshold"] < 0:
print("Distance threshold must be greater than 0")
return False
if args["black_ratio_threshold"] and (args["black_ratio_threshold"] < 0 or args["black_ratio_threshold"] > 1):
print("Black ratio threshold must be in the range 0.0 to 1.0")
return False
if args["pixel_black_threshold"] and (args["pixel_black_threshold"] < 0 or args["pixel_black_threshold"] > 1):
print("Pixel black threshold must be in the range 0.0 to 1.0")
return False
if args["output_resolution"]:
segs = args["output_resolution"].split("x")
if (len(segs) != 2):
print("Output resolution must be in the format WxH")
return False
if (int(segs[0]) <= 0 or int(segs[1]) <= 0):
print("Output resolution must be in the format WxH")
return False
return True

Wyświetl plik

@ -1,4 +1,3 @@
from opendm.video.parameters import Parameters
import datetime
from fractions import Fraction
import io
@ -8,9 +7,11 @@ import cv2
import os
import collections
from PIL import Image
from checkers import BlackFrameChecker, PercentageBlurChecker, SimilarityChecker, ThresholdBlurChecker
from srtparser import SrtFileParser
import piexif
from opendm.video.srtparser import SrtFileParser
from opendm.video.parameters import Parameters
from opendm.video.checkers import BlackFrameChecker, PercentageBlurChecker, SimilarityChecker, ThresholdBlurChecker
class Video2Dataset:
def __init__(self, parameters : Parameters):

Wyświetl plik

@ -34,6 +34,4 @@ onnxruntime==1.12.1
codem==0.24.0
trimesh==3.17.1
pandas==1.5.2
# for video support
piexif==1.1.3
piexif==1.1.3