class mrpt::hwdrivers::CImageGrabber_OpenCV

Overview

Grabs images from any OpenCV-compatible camera or AVI/video file.

Wraps OpenCV’s VideoCapture to provide MRPT observation objects. Supports USB webcams, Video4Linux (V4L) devices, DirectShow (Windows), IEEE-1394 (dc1394 via OpenCV), and AVI/MPEG video files.

Produced observations are of type mrpt::obs::CObservationImage.

Unless playback from AVI files is required, the more generic class mrpt::hwdrivers::CCameraSensor is recommended because it transparently handles many additional backends.

Requires MRPT to be built with OpenCV (MRPT_HAS_OPENCV).

Some code is based on the class CaptureCamera from the Orocos project.

See also:

mrpt::hwdrivers::CCameraSensor, CImageGrabber_dc1394

#include <mrpt/hwdrivers/CImageGrabber_OpenCV.h>

class CImageGrabber_OpenCV
{
public:
    // structs

    struct Impl;

    // construction

    CImageGrabber_OpenCV(int cameraIndex = -1, TCameraType cameraType = CAMERA_CV_AUTODETECT, const TCaptureCVOptions& options = TCaptureCVOptions());
    CImageGrabber_OpenCV(const std::string& AVI_fileName);

    // methods

    bool isOpen() const;
    std::optional<mrpt::obs::CObservationImage> grabFrame();
    bool getObservation(mrpt::obs::CObservationImage& out_observation);
};

Construction

CImageGrabber_OpenCV(int cameraIndex = -1, TCameraType cameraType = CAMERA_CV_AUTODETECT, const TCaptureCVOptions& options = TCaptureCVOptions())

Opens a live camera.

Parameters:

cameraIndex

Device index passed to OpenCV VideoCapture. Use -1 when cameraType is CAMERA_CV_AUTODETECT.

cameraType

Camera backend selector (see TCameraType).

options

Capture options such as resolution and frame rate.

CImageGrabber_OpenCV(const std::string& AVI_fileName)

Opens an AVI or other video file for frame-by-frame playback.

Parameters:

AVI_fileName

Path to the video file.

Methods

bool isOpen() const

Returns true if the camera or video file was opened successfully.

std::optional<mrpt::obs::CObservationImage> grabFrame()

Grabs one frame from the opened camera.

Deprecated Use grabFrame() instead.

Grabs one frame from the opened camera, returning by value.

Parameters:

out_observation

Filled with the captured image and timestamp.

Returns:

false on any error, true on success.

std::nullopt on any error, or the captured observation on success.

bool getObservation(mrpt::obs::CObservationImage& out_observation)

Deprecated Use grabFrame() instead.