sksurgeryimage.acquire.video_writer module

Write stream of frames to file using OpenCV

class sksurgeryimage.acquire.video_writer.ThreadedTimestampedVideoWriter(filename, fps=25, width=640, height=480, codec='MJPG')[source]

Bases: sksurgeryimage.acquire.video_writer.TimestampedVideoWriter

TimestampedVideoWriter that can be run in a thread. Uses Queue.Queue() to store data, which is thread safe.

Frames will be processed as they are added to the queue:

threaded_vw = ThreadedTimestampedVideoWriter(file, fps, w, h) threaded_vw.start()

threaded_vw.add_to_queue(frame, timestamp) threaded_vw.add_to_queue(frame, timestamp) threaded_vw.add_to_queue(frame, timestamp)

threaded_vw.stop()

run()[source]

Write data from the queue to the output file(s).

start()[source]

Start the thread running.

stop()[source]

Stop thread running.

write_frame(frame, timestamp=None)[source]

Add a frame and a timestamp to the queue for writing. Named for consistency with the non-threaded version. Actual writing to disk is done by write_frame_to_disk() :param frame: Image frame :type frame: numpy array :param timestamp: Frame timestamp :type timestamp: datetime.datetime object

write_frame_to_disk()[source]

Get frame and timestamp from queue, then write to output.

class sksurgeryimage.acquire.video_writer.TimestampedVideoWriter(filename, fps=25, width=640, height=480, codec='MJPG')[source]

Bases: sksurgeryimage.acquire.video_writer.VideoWriter

Class to write images and timestamps to disk, inherits from VideoWriter.

Parameters:
  • fps – Frames per second to save to disk.
  • filename – Filename to save output video to. Timestamp file is “filename + ‘timestamps’”
close()[source]

Close/release the output files for video and timestamps.

write_frame(frame, timestamp=None)[source]

Write a frame and timestamp to the output files. If no timestamp provided, write a defualt value. :param frame: Image data :type frame: numpy array :param timestamp: Timestamp data :type timestamp: datetime.datetime object

class sksurgeryimage.acquire.video_writer.VideoWriter(filename, fps=25, width=640, height=480, codec='MJPG')[source]

Bases: object

Class to write images to disk using cv2.VideoWriter.

Parameters:
  • fps – Frames per second to save to disk.
  • filename – Filename to save output video to.
  • width – width of input frame
  • height – height of input frame
check_valid_filename(filename)[source]

Return true if filename is a string.

close()[source]

Close/release the output file for video.

create_output_dir_if_needed()[source]

Check if the directory specified in file path exists and create if not.

set_filename(filename)[source]

Set the filename to write to.

write_frame(frame)[source]

Write a frame to the output file.