Main Content

OpenCV Support

Convert camera parameters, MEX file support, and prebuilt MATLAB® interfaces to OpenCV

The Computer Vision Toolbox™ Interface for OpenCV in MATLAB support package provides these functionalities for OpenCV support:

  • MATLAB functions to convert computed camera parameters between MATLAB and OpenCV formats for camera calibration applications.

  • OpenCV Interface C++ API support files for building MEX files that you can use to call OpenCV functions and integrate OpenCV C++ code into MATLAB. The interface does not support graphics processing unit (GPU). You can use the MEX-based approach to integrate a custom OpenCV function with MATLAB. For more information about the MEX-based approach, see Build MEX-Files for OpenCV Interface.

  • Prebuilt MATLAB interface to the OpenCV library to directly call OpenCV functions from MATLAB without writing C/C++ code. The support package also provides MATLAB functions to pass data back and forth between OpenCV and MATLAB. However, the prebuilt MATLAB interface to the OpenCV does not provide support for integrating custom OpenCV functions with MATLAB.

To use the MEX-based and the prebuilt MATLAB interface to OpenCV support files, you must first download the Computer Vision Toolbox Interface for OpenCV in MATLAB support package. For information about how to download the support package, see Install and Use Computer Vision Toolbox Interface for OpenCV in MATLAB.

Functions

expand all

cameraIntrinsicsFromOpenCVConvert camera intrinsic parameters from OpenCV to MATLAB (Since R2021b)
cameraIntrinsicsToOpenCVConvert camera intrinsic parameters from MATLAB to OpenCV (Since R2021b)
stereoParametersFromOpenCVConvert stereo camera parameters from OpenCV to MATLAB (Since R2021b)
stereoParametersToOpenCVConvert stereo camera parameters from MATLAB to OpenCV (Since R2021b)

OpenCV Interface C++ API

ocvCheckFeaturePointsStructCheck that MATLAB struct represents feature points
ocvStructToKeyPointsConvert MATLAB feature points struct to OpenCV KeyPoint vector
ocvKeyPointsToStructConvert OpenCV KeyPoint vector to MATLAB struct
ocvMxArrayToCvRectConvert a MATLAB struct representing a rectangle to an OpenCV CvRect
ocvCvRectToMxArrayConvert OpenCV CvRect to a MATLAB struct
ocvCvBox2DToMxArrayConvert OpenCV CvBox2D to a MATLAB struct
ocvCvRectToBoundingBox_{DataType}Convert vector<cv::Rect> to M-by-4 mxArray of bounding boxes
ocvMxArrayToSize_{DataType}Convert 2-element mxArray to cv::Size.
ocvMxArrayToImage_{DataType}Convert column major mxArray to row major cv::Mat for image
ocvMxArrayToMat_{DataType}Convert column major mxArray to row major cv::Mat for generic matrix
ocvMxArrayFromImage_{DataType}Convert row major cv::Mat to column major mxArray for image
ocvMxArrayFromMat_{DataType}Convert row major cv::Mat to column major mxArray for generic matrix
ocvMxArrayFromVector_{DataType}Convert numeric vectorT to mxArray
ocvMxArrayFromPoints2fConverts vector<cv::Point2f> to mxArray

OpenCV Interface C++ API GPU

ocvMxGpuArrayToGpuMat_{DataType}Create cv::gpu::GpuMat from mxArray containing GPU data.
ocvMxGpuArrayFromGpuMat_{DataType}Create an mxArray from cv::gpu::GpuMat object
createMatCreate MATLAB interface object for OpenCV Mat class (Since R2021b)
createUMatCreate MATLAB interface object for OpenCV UMat class (Since R2021b)
getBasePtrCreate MATLAB interface object for OpenCV base class (Since R2021b)
getImageRead images stored in MATLAB interface object for OpenCV class (Since R2021b)
keyPointsToStructConvert OpenCV KeyPoints object to MATLAB structure (Since R2021b)
rectToBboxCompute bounding boxes from outputs returned by MATLAB interface object for OpenCV Rect class (Since R2021b)
visionSupportPackagesStart Installer to download, install, or uninstall Computer Vision Toolbox data

Topics