pycharmers.opencv.project module

class pycharmers.opencv.project.cv2Project(args, **kwargs)[source]

Bases: object

OpenCV project wrapper with useful GUI tools.

Parameters

args (Namespace) – Simple object for storing attributes.

Note

  • Image object ( np.ndarray ) has the shape ( height , width , channel )

  • XXX_size attributes are formatted as ( width , height )

cap

VideoCapture (mimic) object. See VideoCaptureCreate

Type

VideoCapture

monitor

Background image. shape= ( monitor_height , monitor_width, 3)

Type

np.ndarray

monitor_height

The height of monitor.

monitor_width

The width of monitor.

original_height

The height of original frame.

Type

int

original_width

The width of original frame.

Type

int

frame_height

The height of resized frame.

Type

int

frame_width

The width of resized frame.

Type

int

frame_dsize

( frame_width , frame_height )

Type

tuple

frame_halfsize

( frame_width//2 , frame_height//2 )

Type

tuple

gui_x

frame_width + gui_margin

Type

int

fps

Frame per seconds.

Type

int

video

Video Writer.

Type

cv2.VideoWriter

video_fn

The file name of video.

Type

str

OtherAttributes:

See cv2ArgumentParser .

init()[source]

Initialize VideoCapture (mimic) object and GUI tools.

Note

  • To run this method, self must have these attributes.
    • winname (str) : Window name.

    • path (str) : Path to video or image.

    • cam (int) : The ID of the web camera.

    • ext (str) : The extension for saved image.

    • gui_width (int) : The width of the GUI tools.

    • gui_margin (int) : The margin of GUI control tools.

    • monitor_size (ListParamProcessor) : Monitor size. ( width , height )

    • autofit (bool) : Whether to fit display size to window size.

    • twitter (bool) : Whether you want to run for tweet. ( display_size will be () )

    • capture (bool) : Whether you want to save as video.

  • After run this method, self will have these attributes.
    • cap (VideoCapture) : VideoCapture (mimic) object. See VideoCaptureCreate

    • monitor (np.ndarray) : Background image. shape= ( monitor_height , monitor_width, 3)

    • monitor_height : The height of monitor.

    • monitor_width : The width of monitor.

    • original_height (int) : The height of original frame.

    • original_width (int) : The width of original frame.

    • frame_height (int) : The height of resized frame.

    • frame_width (int) : The width of resized frame.

    • frame_dsize (tuple) : ( frame_width , frame_height )

    • frame_halfsize (tuple) : ( frame_width//2 , frame_height//2 )

    • gui_x (int) : frame_width + gui_margin

    • fps (int) : Frame per seconds.

    • video (cv2.VideoWriter) : Video Writer.

    • video_fn (str) : The file name of video.

    • fn_prefix (str) : The prefix of filename ( "" if self.path is None else self.path+"." )

wrap(func)[source]

Wrap the function.

Parameters

func (function) – A function that receives and returns frame.

release()[source]

Do the necessary processing at the end