About
This package provides MATLAB® MEX functions that interface with hundreds of OpenCV APIs. The library also contains a C++ class MxArray
that converts between MATLAB's native data type and OpenCV data types. It is suitable for fast prototyping of OpenCV application in MATLAB, use of OpenCV as an external toolbox in MATLAB, and development of custom MEX functions.
Usage
Here is an example to detect faces in an image using the Haar Feature-based Cascade Classifier:
% Load the classifier file
cascade = cv.CascadeClassifier('haarcascade_frontalface_alt2.xml');
% Load the source image
src = imread('people.jpg');
% Convert to grayscale
gr = cv.cvtColor(src, 'RGB2GRAY');
gr = cv.equalizeHist(gr);
% Perform the detection and draw the detected faces
faces = cascade.detect(gr, 'ScaleFactor',1.1, 'MinNeighbors',4);
for i=1:length(faces)
src = cv.rectangle(src, faces{i}, 'Color',[0,255,0], 'Thickness',2);
end
imshow(src)