VSourceLibCamera C++ library v2.0.0

Low-latency video capture C++ library based on Libcamera API. Provides simple interface for easy integration in C++ projects without complexity of Libcamera API.

Overview

VSourceLibCamera C++ library provides low-latency video capture and video source control function based on libcamera API. The library inherits interface from open source VSource interface class. VSource.h file contains data structures VSourceParams class, VSourceCommand enum, VSourceParam enum and includes VSource class declaration. VSourceParams class contains video source params and methods to encode and decode video source params. VSourceCommands enum contains IDs of commands supported by VSource class. VSourceParam enum contains IDs of params supported by VSource class. VSource class depends on libraries: open source Frame library (contains video frame structure and pixel formats) and open source ConfigReader library (provides methods to work with JSON structures (read/write)). Also VSourceLibCamera depends on open source Logger library which provides method to write logs. The library provides auto detection of supported resolution, format and fps. If particular devices doesn't support requested pixel format, resolution or fps, the library will set most appropriate parameters. Library interface:

class VSourceLibCamera : public VSource {
public:
    /// Open video source.
    bool openVSource(std::string& initString);
    /// Init video source by params structure.
    bool initVSource(VSourceParams& params);
    /// Get open status.
    bool isVSourceOpen();
    /// Close video source.
    void closeVSource();
    /// Get new video frame.
    bool getFrame(Frame& frame, int32_t timeoutMsec = 0);
    /// Set video source param.
    bool setParam(VSourceParam id, float value);
    /// Get video source param value.
    float getParam(VSourceParam id);
    /// Get video source params structure.
    VSourceParams getParams();
    /// Execute command.
    bool executeCommand(VSourceCommand id);
};

How to use

Below is a simple example of the program. The program opens the first video device in the system and captures video frames in an infinite loop.

#include <iostream>
#include "VSourceLibCamera.h"

int main(void) {
    // Open video device.
    cr::video::VSource* source = new cr::video::VSourceLibCamera();
    if (!source->openVSource("0;1280;720;NV12"))
        return -1;
    // Init frame.
    cr::video::Frame frame;
    // Main loop.
    while (true) {
        // Wait new frame 1000 msec.
        if (!source->getFrame(frame, 1000))
            continue;
        // Show info about frame.
        std::cout << "New frame " << frame.frameId <<
        " (" << frame.width << "x" << frame.height << ") cycle time: " <<
        (int)source->getParam(cr::video::VSourceParam::CYCLE_TIME_MKS) <<
        " mksec" << std::endl; 
    }
    return 1;
}

Downloads

VSourceLibCamera C++ library programmer’s manual: DOWNLOAD

Price and Terms

The VSourceLibCamera C++ library is supplied under a license in source code. Library pricing is available upon request info@constantrobotics.com