TakeOne Blog

Conspect for OpenCV: Introduction

Some notable notes from https://docs.opencv.org/4.x/d1/dfb/intro.html.

  1. Automatic memory management
    • ref counting
    • cv::Mat and others contain ref to buffer
    • cv::Mat::clone to copy buffer
    • use cv::Ptr for high-level class to include OpenCV ref-counting
    • if cv::Mat instance is reused with different dimensions (e.g. in cap >> frame), storage is automatically reallocated
  2. Saturation arithmetics
    • use cv::saturate_cast<cv::uchar> to cast a value into the acceptable range
  3. Fixed pixel types
    • because OpenCV limits the use of templates use CV_ types for element
    • CV_8U and so on are for scalars
    • CV_8UC2 or CV_8UYC(2) or CV_MAKETYPE(img.depth(), 1) is for 2-channel values
    • more complex elements are not possible in OpenCV arrays
    • algorithms are limited in what array element types they handle
  4. InputArray and OutputArray
    • use cv::Matx<...> - for small matrixes
    • InputArray and OutputArray are any supported containers Mat, Matx, Vec, Scalar, or std::vector
    • use cv::noArray() as a dummy for optional parameters
  5. Error handling
    • in case of error, all intermediate buffers are automatically deallocated
  6. OpenCV functions or methods of different instances can be used from different threads
    • you cannot call a method of the same instance from two different threads simultaneously, as the internal data is not protected (unless you synchronize access, of course)

Maybe explore next:

#conspect #opencv