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 support files contain graphics processing unit (GPU) support. 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
cameraIntrinsicsToOpenCVConvert camera intrinsic parameters from MATLAB to OpenCV
stereoParametersFromOpenCVConvert stereo camera parameters from OpenCV to MATLAB
stereoParametersToOpenCVConvert stereo camera parameters from MATLAB to OpenCV

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
createUMatCreate MATLAB interface object for OpenCV UMat class
getBasePtrCreate MATLAB interface object for OpenCV base class
getImageRead images stored in MATLAB interface object for OpenCV class
keyPointsToStructConvert OpenCV KeyPoints object to MATLAB structure
rectToBboxCompute bounding boxes from outputs returned by MATLAB interface object for OpenCV Rect class
visionSupportPackagesStart installer to download, install, or uninstall Computer Vision Toolbox data

Topics

Install and Use Computer Vision Toolbox Interface for OpenCV in MATLAB

Download and install support package for integrating OpenCV and MATLAB.

Build MEX-Files for OpenCV Interface

Create and test MEX- file based OpenCV interface.

Use Prebuilt MATLAB Interface to OpenCV

To call and execute OpenCV functions directly from MATLAB, use the prebuilt MATLAB interface.

Featured Examples