Skip to content
This repository
tree: df31825522
Fetching contributors…

Cannot retrieve contributors at this time

file 132 lines (125 sloc) 6.102 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
classdef VideoCapture < handle
    %VIDEOCAPTURE VideoCapture wrapper class
    %
    % Class for video capturing from video files or cameras. The class
    % provides Matlab API for capturing video from cameras or for reading
    % video files. Here is how the class can be used:
    %
    % cap = cv.VideoCapture;
    % pause(3); % Note below
    % for t = 1:30
    % imshow(cap.read);
    % pause(0.1);
    % end
    %
    % ## Note
    % In some environment, there is a concurrency issue during camera
    % initialization. To avoid unexpected crash, pause for seconds after
    % the initialization of VideoCapture object.
    %
    % See also cv.VideoCapture.VideoCapture cv.VideoCapture.read
    % cv.VideoCapture.get cv.VideoCapture.set
    %
    
    properties (SetAccess = private)
        % Object ID
        id
    end
    
    methods
        function this = VideoCapture(filename)
            %VIDEOCAPTURE Create a new VideoCapture object
            %
            % cap = cv.VideoCapture
            % cap = cv.VideoCapture(devid)
            % cap = cv.VideoCapture(filename)
            %
            % VideoCapture create a new instance. With no argument, it
            % connects to the default camera device found in the system.
            % You can specify camera devices by devid, an integer value
            % starting from 0. You can also specify a filename to open a
            % video file.
            %
            % See also cv.VideoCapture
            %
            if nargin < 1, filename = 0; end
            this.id = VideoCapture_(filename);
        end
        
        function delete(this)
            %DELETE Destructor of VideoCapture object
            VideoCapture_(this.id, 'delete');
        end
        
        function frame = read(this)
            %READ Grabs, decodes and returns the next video frame
            %
            % frame = cap.read()
            %
            % The method captures the next video frame and return it. If
            % capturing fails, empty array will be returned instead.
            %
            % See also cv.VideoCapture
            %
            frame = VideoCapture_(this.id, 'read');
        end
        
        function value = get(this, key)
            %GET Returns the specified VideoCapture property
            %
            % value = cap.get(PropertyName)
            %
            % The method returns a Property value of VideoCapture.
            % PropertyName can be one of the followings:
            %
            % 'PosMsec' Current position of the video file in milliseconds or video capture timestamp.
            % 'PosFrames' 0-based index of the frame to be decoded/captured next.
            % 'AVIRatio' Relative position of the video file: 0 - start of the film, 1 - end of the film.
            % 'FrameWidth' Width of the frames in the video stream.
            % 'FrameHeight' Height of the frames in the video stream.
            % 'FPS' Frame rate.
            % 'FourCC' 4-character code of codec.
            % 'FrameCount' Number of frames in the video file.
            % 'Format' Format of the Mat objects returned by retrieve() .
            % 'Mode' Backend-specific value indicating the current capture mode.
            % 'Brightness' Brightness of the image (only for cameras).
            % 'Contrast' Contrast of the image (only for cameras).
            % 'Saturation' Saturation of the image (only for cameras).
            % 'Hue' Hue of the image (only for cameras).
            % 'Gain' Gain of the image (only for cameras).
            % 'Exposure' Exposure (only for cameras).
            % 'ConvertRGB' Boolean flags indicating whether images should be converted to RGB.
            % 'Rectification' Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
            %
            % See also cv.VideoCapture
            %
            value = VideoCapture_(this.id, 'get', key);
        end
        
        function set(this, key, value)
            %SET Sets a property in the VideoCapture.
            %
            % cap.set(PropertyName, value)
            %
            % The method set a Property value of VideoCapture.
            % PropertyName can be one of the followings:
            %
            % 'PosMsec' Current position of the video file in milliseconds or video capture timestamp.
            % 'PosFrames' 0-based index of the frame to be decoded/captured next.
            % 'AVIRatio' Relative position of the video file: 0 - start of the film, 1 - end of the film.
            % 'FrameWidth' Width of the frames in the video stream.
            % 'FrameHeight' Height of the frames in the video stream.
            % 'FPS' Frame rate.
            % 'FourCC' 4-character code of codec.
            % 'FrameCount' Number of frames in the video file.
            % 'Format' Format of the Mat objects returned by retrieve() .
            % 'Mode' Backend-specific value indicating the current capture mode.
            % 'Brightness' Brightness of the image (only for cameras).
            % 'Contrast' Contrast of the image (only for cameras).
            % 'Saturation' Saturation of the image (only for cameras).
            % 'Hue' Hue of the image (only for cameras).
            % 'Gain' Gain of the image (only for cameras).
            % 'Exposure' Exposure (only for cameras).
            % 'ConvertRGB' Boolean flags indicating whether images should be converted to RGB.
            % 'Rectification' Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)
            %
            % See also cv.VideoCapture
            %
            VideoCapture_(this.id, 'set', key, value);
        end
    end
    
end
Something went wrong with that request. Please try again.