provide filename for video output
This commit is contained in:
@@ -24,8 +24,9 @@ def cap_init(cap: cv.VideoCapture):
|
|||||||
|
|
||||||
|
|
||||||
class Detector(abc.ABC):
|
class Detector(abc.ABC):
|
||||||
def __init__(self, source: str, detector: list[BoardDetector]):
|
def __init__(self, source: str, detector: list[BoardDetector], out_file: str|None = None):
|
||||||
self.detector = detector
|
self.detector = detector
|
||||||
|
self.out_file = out_file
|
||||||
self.device_id = None
|
self.device_id = None
|
||||||
self.src_video = None
|
self.src_video = None
|
||||||
self.src_images = None
|
self.src_images = None
|
||||||
@@ -152,7 +153,8 @@ class Detector(abc.ABC):
|
|||||||
|
|
||||||
img_scaled = cv.resize(img, dsize=None, fx=0.5, fy=0.5)
|
img_scaled = cv.resize(img, dsize=None, fx=0.5, fy=0.5)
|
||||||
cv.imshow('img', img_scaled)
|
cv.imshow('img', img_scaled)
|
||||||
out = out_writer(out, img_scaled)
|
if self.out_file is not None:
|
||||||
|
out = out_writer(out, img_scaled, filename=self.out_file)
|
||||||
|
|
||||||
if frame_go:
|
if frame_go:
|
||||||
frame_num += 1
|
frame_num += 1
|
||||||
@@ -162,11 +164,11 @@ class Detector(abc.ABC):
|
|||||||
|
|
||||||
cv.destroyAllWindows()
|
cv.destroyAllWindows()
|
||||||
|
|
||||||
def out_writer(writer: cv.VideoWriter|None, frame: np.ndarray|None) -> cv.VideoWriter:
|
def out_writer(writer: cv.VideoWriter|None, frame: np.ndarray|None, filename: str = None) -> cv.VideoWriter:
|
||||||
if writer is None:
|
if writer is None:
|
||||||
fourcc = cv.VideoWriter.fourcc(*"mp4v")
|
fourcc = cv.VideoWriter.fourcc(*"mp4v")
|
||||||
frame_size = (frame.shape[1], frame.shape[0])
|
frame_size = (frame.shape[1], frame.shape[0])
|
||||||
writer = cv.VideoWriter(filename=f"{RESULTS_FOLDER}/out.mp4", fourcc=fourcc, fps=30.0, frameSize=frame_size)
|
writer = cv.VideoWriter(filename=f"{RESULTS_FOLDER}/{filename}", fourcc=fourcc, fps=30.0, frameSize=frame_size)
|
||||||
|
|
||||||
if writer is not None:
|
if writer is not None:
|
||||||
if frame is not None:
|
if frame is not None:
|
||||||
@@ -208,6 +210,9 @@ def main():
|
|||||||
ap.add_argument("-p", "--name", type=str,
|
ap.add_argument("-p", "--name", type=str,
|
||||||
default='default',
|
default='default',
|
||||||
help="Name of project")
|
help="Name of project")
|
||||||
|
ap.add_argument("-o", "--output",
|
||||||
|
action='store_true',
|
||||||
|
help="Enable video output")
|
||||||
args = vars(ap.parse_args())
|
args = vars(ap.parse_args())
|
||||||
|
|
||||||
msg_size = 3
|
msg_size = 3
|
||||||
@@ -224,7 +229,11 @@ def main():
|
|||||||
det = BoardDetectorCharuco(f"{args["name"]}-{n}", args["dict_type"], board_id, (args["board_width"], args["board_height"]))
|
det = BoardDetectorCharuco(f"{args["name"]}-{n}", args["dict_type"], board_id, (args["board_width"], args["board_height"]))
|
||||||
board_detector.append(det)
|
board_detector.append(det)
|
||||||
|
|
||||||
detector = Detector(args["source"], board_detector)
|
out_file = None
|
||||||
|
if args["output"]:
|
||||||
|
out_file = args["name"]
|
||||||
|
|
||||||
|
detector = Detector(args["source"], board_detector, out_file=out_file)
|
||||||
detector.board_image_generate(margin_length=args["margin_length"])
|
detector.board_image_generate(margin_length=args["margin_length"])
|
||||||
detector.calibrate_load()
|
detector.calibrate_load()
|
||||||
detector.process()
|
detector.process()
|
||||||
|
|||||||
Reference in New Issue
Block a user