PDL::OpenCV::Videoio - PDL bindings for OpenCV VideoCapture, VideoWriter
use PDL::OpenCV::Videoio;
None.
Class for video capturing from video files, image sequences or cameras.
The class provides C++ API for capturing video from cameras or for reading video files and image sequences. Here is how the class can be used: @include samples/cpp/videocapture_basic.cpp @note In @ref videoio_c "C API" the black-box structure `CvCapture` is used instead of %VideoCapture. @note - (C++) A basic sample on using the %VideoCapture interface can be found at `OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp` - (Python) A basic sample on using the %VideoCapture interface can be found at `OPENCV_SOURCE_CODE/samples/python/video.py` - (Python) A multi threaded video processing sample can be found at `OPENCV_SOURCE_CODE/samples/python/video_threaded.py` - (Python) %VideoCapture sample showcasing some features of the Video4Linux2 backend `OPENCV_SOURCE_CODE/samples/python/video_v4l2.py`
Default constructor
$obj = PDL::OpenCV::VideoCapture->new;
@note In @ref videoio_c "C API", when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr\<CvCapture\> that calls cvReleaseCapture() automatically in the destructor.
Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
$obj = PDL::OpenCV::VideoCapture->new2($filename); # with defaults $obj = PDL::OpenCV::VideoCapture->new2($filename,$apiPreference);
@overload
Parameters:
it can be: - name of video file (eg. `video.avi`) - or image sequence (eg. `img_%02d.jpg`, which will read samples like `img_00.jpg, img_01.jpg, img_02.jpg, ...`) - or URL of video stream (eg. `protocol://host:port/script_name?script_params|auth`) - or GStreamer pipeline string in gst-launch tool format in case if GStreamer is used as backend Note that each video stream or IP camera feed has its own URL scheme. Please refer to the documentation of source stream to know the right URL.
preferred Capture API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW.
See also: cv::VideoCaptureAPIs
Signature: (int [phys] apiPreference(); int [phys] params(n4d0); char * klass; StringWrapper* filename; [o] VideoCaptureWrapper * res)
Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters
$obj = PDL::OpenCV::VideoCapture->new3($filename,$apiPreference,$params);
@overload The `params` parameter allows to specify extra parameters encoded as pairs `(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)`. See cv::VideoCaptureProperties
VideoCapture_new3 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Opens a camera for video capturing
$obj = PDL::OpenCV::VideoCapture->new4($index); # with defaults $obj = PDL::OpenCV::VideoCapture->new4($index,$apiPreference);
id of the video capturing device to open. To open default camera using default backend just pass 0. (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY)
preferred Capture API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L.
Signature: (int [phys] index(); int [phys] apiPreference(); int [phys] params(n4d0); char * klass; [o] VideoCaptureWrapper * res)
Opens a camera for video capturing with API Preference and parameters
$obj = PDL::OpenCV::VideoCapture->new5($index,$apiPreference,$params);
VideoCapture_new5 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Opens a video file or a capturing device or an IP video stream for video capturing.
$res = $obj->open($filename); # with defaults $res = $obj->open($filename,$apiPreference);
@overload Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY) The method first calls VideoCapture::release to close the already opened file or camera.
Returns: `true` if the file has been successfully opened
Signature: (int [phys] apiPreference(); int [phys] params(n4d0); byte [o,phys] res(); VideoCaptureWrapper * self; StringWrapper* filename)
$res = $obj->open2($filename,$apiPreference,$params);
@overload The `params` parameter allows to specify extra parameters encoded as pairs `(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)`. See cv::VideoCaptureProperties The method first calls VideoCapture::release to close the already opened file or camera.
VideoCapture_open2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
$res = $obj->open3($index); # with defaults $res = $obj->open3($index,$apiPreference);
@overload Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY) The method first calls VideoCapture::release to close the already opened file or camera.
Returns: `true` if the camera has been successfully opened.
Signature: (int [phys] index(); int [phys] apiPreference(); int [phys] params(n4d0); byte [o,phys] res(); VideoCaptureWrapper * self)
Returns true if video capturing has been initialized already.
$res = $obj->open4($index,$apiPreference,$params);
VideoCapture_open4 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
$res = $obj->isOpened;
If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns true.
Closes video file or capturing device.
$obj->release;
The method is automatically called by subsequent VideoCapture::open and by VideoCapture destructor. The C function also deallocates memory and clears *capture pointer.
Grabs the next frame from video file or capturing device.
$res = $obj->grab;
The method/function grabs the next frame from video file or camera and returns true (non-zero) in the case of success. The primary use of the function is in multi-camera environments, especially when the cameras do not have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames from different cameras will be closer in time. Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the correct way of retrieving data from it is to call VideoCapture::grab() first and then call VideoCapture::retrieve() one or more times with different values of the channel parameter. @ref tutorial_kinect_openni
Returns: `true` (non-zero) in the case of success.
Signature: ([o,phys] image(l2,c2,r2); int [phys] flag(); byte [o,phys] res(); VideoCaptureWrapper * self)
Decodes and returns the grabbed video frame. NO BROADCASTING.
($image,$res) = $obj->retrieve; # with defaults ($image,$res) = $obj->retrieve($flag);
The method decodes and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns an empty image (with %cv::Mat, test it with Mat::empty()). @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage and then do whatever you want with the copy.
the video frame is returned here. If no frames has been grabbed the image will be empty.
it could be a frame index or a driver specific flag
Returns: `false` if no frames has been grabbed
See also: read()
VideoCapture_retrieve ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: ([o,phys] image(l2,c2,r2); byte [o,phys] res(); VideoCaptureWrapper * self)
Grabs, decodes and returns the next video frame. NO BROADCASTING.
($image,$res) = $obj->read;
The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()). @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage and then do whatever you want with the copy.
VideoCapture_read ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Sets a property in the VideoCapture.
$res = $obj->set($propId,$value);
@ref videoio_flags_others @note Even if it returns `true` this doesn't ensure that the property value has been accepted by the capture device. See note in VideoCapture::get()
Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from
Value of the property.
Returns: `true` if the property is supported by backend used by the VideoCapture instance.
Returns the specified VideoCapture property
$res = $obj->get($propId);
@ref videoio_flags_others @note Reading / writing properties involves many layers. Some unexpected result might happens along this chain.
{.txt} VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware
The returned value might be different from what really used by the device or it could be encoded using device dependent rules (eg. steps or percentage). Effective behaviour depends from device driver and API Backend
Returns: Value for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoCapture instance.
Returns used backend API name
$res = $obj->getBackendName;
@note Stream should be opened.
$obj->setExceptionMode($enable);
Switches exceptions mode * * methods raise exceptions if not successful instead of returning an error code
$res = $obj->getExceptionMode;
Video writer class.
The class provides C++ API for writing video files or image sequences.
Default constructors
$obj = PDL::OpenCV::VideoWriter->new;
The constructors/functions initialize video writers. - On Linux FFMPEG is used to write videos; - On Windows FFMPEG or MSWF or DSHOW is used; - On MacOSX AVFoundation is used.
Signature: (int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n5=2); byte [phys] isColor(); char * klass; StringWrapper* filename; [o] VideoWriterWrapper * res)
$obj = PDL::OpenCV::VideoWriter->new2($filename,$fourcc,$fps,$frameSize); # with defaults $obj = PDL::OpenCV::VideoWriter->new2($filename,$fourcc,$fps,$frameSize,$isColor);
@overload @b Tips: - With some backends `fourcc=-1` pops up the codec selection dialog from the system. - To save image sequence use a proper filename (eg. `img_%02d.jpg`) and `fourcc=0` OR `fps=0`. Use uncompressed image format (eg. `img_%02d.BMP`) to save raw frames. - Most codecs are lossy. If you want lossless video file you need to use a lossless codecs (eg. FFMPEG FFV1, Huffman HFYU, Lagarith LAGS, etc...) - If FFMPEG is enabled, using `codec=0; fps=0;` you can create an uncompressed (raw) video file.
Name of the output video file.
4-character code of codec used to compress the frames. For example, VideoWriter::fourcc('P','I','M','1') is a MPEG-1 codec, VideoWriter::fourcc('M','J','P','G') is a motion-jpeg codec etc. List of codes can be obtained at [Video Codecs by FOURCC](http://www.fourcc.org/codecs.php) page. FFMPEG backend with MP4 container natively uses other values as fourcc code: see [ObjectType](http://mp4ra.org/#/codecs), so you may receive a warning message from OpenCV about fourcc code conversion.
Framerate of the created video stream.
Size of the video frames.
If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames.
VideoWriter_new2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] apiPreference(); int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n6=2); byte [phys] isColor(); char * klass; StringWrapper* filename; [o] VideoWriterWrapper * res)
$obj = PDL::OpenCV::VideoWriter->new3($filename,$apiPreference,$fourcc,$fps,$frameSize); # with defaults $obj = PDL::OpenCV::VideoWriter->new3($filename,$apiPreference,$fourcc,$fps,$frameSize,$isColor);
@overload The `apiPreference` parameter allows to specify API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_GSTREAMER.
VideoWriter_new3 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n5=2); int [phys] params(n6d0); char * klass; StringWrapper* filename; [o] VideoWriterWrapper * res)
$obj = PDL::OpenCV::VideoWriter->new4($filename,$fourcc,$fps,$frameSize,$params);
@overload * The `params` parameter allows to specify extra encoder parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) * see cv::VideoWriterProperties
VideoWriter_new4 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] apiPreference(); int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n6=2); int [phys] params(n7d0); char * klass; StringWrapper* filename; [o] VideoWriterWrapper * res)
$obj = PDL::OpenCV::VideoWriter->new5($filename,$apiPreference,$fourcc,$fps,$frameSize,$params);
VideoWriter_new5 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n5=2); byte [phys] isColor(); byte [o,phys] res(); VideoWriterWrapper * self; StringWrapper* filename)
Initializes or reinitializes video writer.
$res = $obj->open($filename,$fourcc,$fps,$frameSize); # with defaults $res = $obj->open($filename,$fourcc,$fps,$frameSize,$isColor);
The method opens video writer. Parameters are the same as in the constructor VideoWriter::VideoWriter. The method first calls VideoWriter::release to close the already opened file.
Returns: `true` if video writer has been successfully initialized
VideoWriter_open ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] apiPreference(); int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n6=2); byte [phys] isColor(); byte [o,phys] res(); VideoWriterWrapper * self; StringWrapper* filename)
$res = $obj->open2($filename,$apiPreference,$fourcc,$fps,$frameSize); # with defaults $res = $obj->open2($filename,$apiPreference,$fourcc,$fps,$frameSize,$isColor);
VideoWriter_open2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n5=2); int [phys] params(n6d0); byte [o,phys] res(); VideoWriterWrapper * self; StringWrapper* filename)
$res = $obj->open3($filename,$fourcc,$fps,$frameSize,$params);
VideoWriter_open3 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: (int [phys] apiPreference(); int [phys] fourcc(); double [phys] fps(); indx [phys] frameSize(n6=2); int [phys] params(n7d0); byte [o,phys] res(); VideoWriterWrapper * self; StringWrapper* filename)
$res = $obj->open4($filename,$apiPreference,$fourcc,$fps,$frameSize,$params);
VideoWriter_open4 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Returns true if video writer has been successfully initialized.
Closes the video writer.
The method is automatically called by subsequent VideoWriter::open and by the VideoWriter destructor.
Signature: ([phys] image(l2,c2,r2); VideoWriterWrapper * self)
Writes the next video frame
$obj->write($image);
The function/method writes the specified image to video file. It must have the same size as has been specified when opening the video writer.
The written frame. In general, color images are expected in BGR format.
VideoWriter_write ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Sets a property in the VideoWriter.
@ref videoio_flags_others
Property identifier from cv::VideoWriterProperties (eg. cv::VIDEOWRITER_PROP_QUALITY) or one of
Returns: `true` if the property is supported by the backend used by the VideoWriter instance.
Returns the specified VideoWriter property
Returns: Value for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoWriter instance.
Concatenates 4 chars to a fourcc code
$res = PDL::OpenCV::VideoWriter::fourcc($c1,$c2,$c3,$c4);
This static method constructs the fourcc code of the codec to be used in the constructor VideoWriter::VideoWriter or VideoWriter::open.
Returns: a fourcc code
To install PDL::OpenCV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDL::OpenCV
CPAN shell
perl -MCPAN -e shell install PDL::OpenCV
For more information on module installation, please visit the detailed CPAN module installation guide.