Skip to main content

Camera Capture

Introduction

These functions are responsible for capturing images from a camera.

VxDiscoverCameraDevice

Function:

int VxDiscoverCameraDevices(std::vector<std::string>& devList)

Function Description:

  • This Function retrieves a list of available camera devices and stores the device names in a vector of wide strings.

Parameter Description:

  • devList : A vector of wide strings to store the retrieved devices.
  • Return:
    • C++ : devList.size()
    • Python : tuple(devList.size(), devList)

Example:

// declare the vector to save the list of devices
std::vector<std::string> dev_list;
// discover the devices
VxDiscoverCameraDevices(dev_list);

VxInitialCameraDevice

Function:

std::shared_ptr<VxCamera> VxInitialCameraDevice(int devIdx)

Function Description:

  • This function initializes a VxCamera instance by selecting an index from the device list retrieved from VxDiscoverCameraDevice().
  • It returns a shared pointer to the created VxCamera object, enabling shared ownership and automatic memory management.

Parameter Description:

  • devIdx : An integer specifying the index of the device to be opened in the device list.
  • return a shared pointer to the initialized device, return nullptr = FAIL

Example:

int devIdx;
// initial the camera to obtain the pointer point to camera device
VxInitialCameraDevice(devIdx);

VxOpen

Function:

int VxOpen(std::shared_ptr<VxCamera> vxcam)

Function Description:

  • This function is used to open a device obtained by calling VxInitialCameraDevice().

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • return 0 = PASS, return -1 = FAIL.

Example:

// initial the camera to obtain the pointer point to the camera device
auto vxcam = VxInitialCameraDevice(dev_idx);
// open the camera
VxOpen(vxcam);

VxClose

Function:

int VxClose(std::shared_ptr<VxCamera> vxcam)

Function Description:

  • This function is used to close a device obtained by calling VxInitialCameraDevice().

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • return 0 = PASS, return -1 = FAIL.

Example:

// close the camera
VxClose(vxcam);

VxIsVizionCamera

Function:

int VxIsVizionCamera(std::shared_ptr<VxCamera> vxcam)

Function Description:

  • Verify whether the VxCamera device is TechNexion UVC or MIPI product or not.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • return 0 = PASS, return -1 = FAIL.

Example:

// check the type of camera
VxIsVizionCamera(vxcam);

VxGetDeviceName

Function:

int VxGetDeviceName(std::shared_ptr<VxCamera> vxcam, std::string& deviceName)

Function Description:

  • This function is used to obtain the device name.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • deviceName : A reference of string variable to store the device name.
  • Return:
    • C++ : return 0 = PASS, return -1 = FAIL.
    • Python : tuple(return_code, deviceName)

      return_code : return 0 = PASS, return -1 = FAIL

Example:

std::string deviceName;
// get the device name of camera
VxGetDeviceName(vxcam, deviceName);

VxGetDeviceInterfaceType

Function:

int VxGetDeviceInterfaceType(std::shared_ptr<VxCamera> vxcam, VX_CAMERA_INTERFACE_TYPE& type);

Function Description:

  • This function is used to obtain the type of device interface.
  • The device interface type is set as VX_CAMERA_INTERFACE_TYPE format.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().

  • type : A VX_CAMERA_INTERFACE_TYPE format variable, which is used to store the interface type.

  • Return:

    • C++ : return 0 = PASS, return -1 = FAIL
    • Python : tuple(return_code, type)

      return_code : return 0 = PASS, return -1 = FAIL

  • VX_CAMERA_INTERFACE_TYPE format:

    enum class VX_CAMERA_INTERFACE_TYPE {
    INTERFACE_USB = 0,
    INTERFACE_MIPI_CSI2,
    INTERFACE_ETHERNET,
    };

Example:

VX_CAMERA_INTERFACE_TYPE type;
// get the device interface type of camera
VxGetDeviceInterfaceType(vxcam, type);

VxGetHardwareID

Function:

int VxGetHardwareID(std::shared_ptr<VxCamera> vxcam, std::string& hwId)

Function Description:

  • This function is used to obtain the hardware ID of the device.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • hwId : A reference of string variable to store the hardware ID.
  • Return:
    • C++ : return 0 = PASS, return -1 = FAIL
    • Python : tuple(return_code, hwId)

      return_code : return 0 = PASS, return -1 = FAIL

Example:

std::string hwId;
// get the hardware ID of camera
VxGetHardwareID(vxcam, hwId);

VxGetUSBDeviceSpeed

Function:

int VxGetUSBDeviceSpeed(std::shared_ptr<VxCamera> vxcam, VX_USB_DEVICE_SPEED& speed)

Function Description:

  • This function is used to obtain the speed of the USB device.
  • The speed is set as VX_USB_DEVICE_SPEED format.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().

  • speed : A reference of VX_USB_DEVICE_SPEED format variable to store the speed.

  • Return:

    • C++ : return 0 = PASS, return -1 = FAIL
    • Python : tuple(return_code, speed)

      return_code : return 0 = PASS, return -1 = FAIL

  • VX_USB_DEVICE_SPEED format:

    enum class VX_USB_DEVICE_SPEED {
    USB_DEVICE_SPEED_LOW,
    USB_DEVICE_SPEED_FULL,
    USB_DEVICE_SPEED_HIGH,
    USB_DEVICE_SPEED_SUPER,
    USB_DEVICE_SPEED_SUPER_PLUS,
    USB_DEVICE_SPEED_UNKNOWN
    };

Example:

VX_USB_DEVICE_SPEED speed;
// get the hardware ID of camera
VxGetUSBDeviceSpeed(vxcam, speed);

VxGetFormatList

Function:

int VxGetFormatList(std::shared_ptr<VxCamera> vxcam, std::vector<VxFormat>& fmtList)

Function Description:

  • This function is used to obtain the list of formats from the VxCamera device.
    info

    To retrieve the available formats of a VxCamera device, first create a vector of VxFormat structures, and then call VxGetFormatList function passing in the VxCamera object and the vector as parameters.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().

  • fmtList : A vector of VxFormat structures. The function will populate this vector with the available formats.

  • Return:

    • C++ : return 0 = PASS, return -1 = FAIL
    • Python : tuple(return_code, fmtList)

      return_code : return 0 = PASS, return -1 = FAIL

  • VxFormat structures:

struct VxFormat {
uint8_t mediatypeIdx;
uint16_t width;
uint16_t height;
uint16_t framerate;
VX_IMAGE_FORMAT format;
};
  • VX_IMAGE_FORMAT format:
enum class VX_IMAGE_FORMAT {
NONE = 0,
YUY2,
UYVY,
NV12,
MJPG,
};

Example:

std::vector<VxFormat> fmt_list;
// get the list of formats from the camera
VxGetFormatList(vxcam, fmt_list);

VxSetFormat

Function:

int VxSetFormat(std::shared_ptr<VxCamera> vxcam, VxFormat fmt)

Function Description:

  • This function is used to set the specified format to the VxCamera device.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • fmt : A VxFormat format to be set. The format must be obtained from the**** VxGetFormatList().
  • return 0 = PASS, return -1 = FAIL.

Example:

// get format list
std::vector<VxFormat> fmt_list;
VxGetFormatList(cam, fmt_list);
// set the format
VxSetFormat(vxcam, fmt_list[0]);

VxStartStreaming

Function:

int VxStartStreaming(std::shared_ptr<VxCamera> vxcam)

Function Description:

  • This function is for starting streaming on the device.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • return 0 = PASS, return -1 = FAIL.

Example:

// start streaming the camera
VxStartStreaming(vxcam);

VxStopStreaming

Function:

int VxStopStreaming(std::shared_ptr<VxCamera> vxcam)

Function Description:

  • This function is for stopping streaming on the VxCamera device.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • return 0 = PASS, return -1 = FAIL.

Example:

// stop streaming the camera
VxStopStreaming(vxcam);

VxGetImage

Function:

VX_CAPTURE_RESULT VxGetImage(std::shared_ptr<VxCamera> vxcam,
uint8_t* data,
int* dataSize,
uint16_t timeout)

Function Description:

  • This function is used to capture the image from the VxCamera device.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • data : A pointer to the buffer that stores the raw image data.
  • dataSize : A pointer to an integer that stores the size of the raw image data.
  • timeout : The timeout value in milliseconds.
  • fmt : A VxFormat format to be set.

Return Values:

  • C++:

    • VX_SUCCESS = 0
    • VX_TIMEOUT = -1
    • VX_CAM_OCCUPIED = -2
    • VX_OTHER_ERROR = -3
    • VX_BUFFER_CORRUPTED = -4
  • Python:

    • tuple(return_code, img)

      return_code : return value same as C++
      img is stored in a numpy array

Example:

// get format list
std::vector<VxFormat> fmt_list;
VxGetFormatList(cam, fmt_list);
// get mjpg format
VxFormat mjpg_fmt;
for (auto fmt : fmt_list) {
// find MJPG format
if (fmt.format == VX_IMAGE_FORMAT::MJPG) {
mjpg_fmt = fmt;
}
}

// set the MJPG format
VxSetFormat(cam, mjpg_fmt);
// start streaming
VxStartStreaming(cam);

// get the MJPG format image
uint8_t* raw_data = new uint8_t[3840 * 2160 * 2];
int raw_size = 0;
VxGetImage(cam, raw_data, &raw_size, 2500);

VxGetImageFd

warning

This function is only supported in C++ and works only when the image buffer is allocated using a DMA buffer.

Function:

VX_CAPTURE_RESULT VxGetImageFd(std::shared_ptr<VxCamera> vxcam,
int* dmaBufferFd,
uint16_t timeout)

Function Description:

  • This function is used to capture the image from the device and store it in a DMA buffer.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • dmaBufferFd : A pointer to DMA buffer file descriptor that stores the raw image data.
  • timeout : The timeout value in milliseconds.

Return Values:

  • VX_SUCCESS = 0
  • VX_TIMEOUT = -1
  • VX_CAM_OCCUPIED = -2
  • VX_OTHER_ERROR = -3
  • VX_BUFFER_CORRUPTED = -4

Example:

int dmaBufferFd;
uint16_t timeout;
// get the image to DMA buffer
VxGetImageFd(vxcam, dmaBufferFd, timeout);

VxReleaseImageFd

warning

This function is only supported in C++ and works only when the image buffer is allocated using a DMA buffer.

Function:

int VxReleaseImageFd(std::shared_ptr<VxCamera> vxcam, int dmaBufferFd)

Function Description:

  • This function is used to release the image stored in a DMA buffer.

Parameter Description:

  • vxcam : A pointer shared ownership of a camera obtained from VxInitialCameraDevice().
  • dmaBufferFd : A DMA buffer file descriptor that stores the raw image data.
  • return 0 = PASS, return -1 = FAIL.

Example:

int dmaBufferFd;
// release the image from the DMA buffer
VxReleaseImageFd(vxcam, dmaBufferFd);