原来在一个优秀的计算机视觉博客中看到过,这次要用,记下这个网址:
http://www.cs.stonybrook.edu/~kyamagu/mexopencv/
需要的童鞋自取。
初体验:
我的环境win7+VS2010+matlab2011b+opencv2.4.5
下载mexopencv-master.zip解压后,按README.markdown,在matlab2011b中输入命令
>mexopencv.make('opencv_path', 'D:\Program Files\opencv244')
----------------------------------------------------------------------------------------------
如果使用VS2008会提示缺头文件
'stdint.h': No such file or directory
在这里找到了头文件放入mexopencv-master的include文件夹中即可:
http://msinttypes.googlecode.com/svn/trunk/stdint.h
----------------------------------------------------------------------------------------------
mex成功后给出如下信息:
To finish the setup, add OpenCV bin folder to the systemPATH, then restart MATLAB for changes to take effect. set PATH=%PATH%;D:\Program Files\opencv\build\x64\vc10\binTo use mexopencv, add its root folder to MATLAB search path.
环境变量设置后,运行下面的例子报错(估计是因为’haarcascade_frontalface_alt.xml‘这个分类器不存在):
% Load a face detector and an image detector = cv.CascadeClassifier('haarcascade_frontalface_alt.xml'); im = imread('myface.jpg'); % Preprocess gr = cv.cvtColor(im, 'RGB2GRAY'); gr = cv.equalizeHist(gr); % Detect boxes = detector.detect(gr, 'ScaleFactor', 1.3, ... 'MinNeighbors', 2, ... 'MinSize', [30, 30]); % Draw results imshow(im); for i = 1:numel(boxes) rectangle('Position', boxes{i}, ... 'EdgeColor', 'g'); end
错误如下:
Error using CascadeClassifier_ Invalid path or file specified Error in cv.CascadeClassifier (line 33) this.id = CascadeClassifier_(filename);
可以运行第2个例子:
%Would you like to use a camera input? No problem. camera = cv.VideoCapture(); pause(2); for i = 1:50 % Capture and show frame frame = camera.read; imshow(frame); pause(0.3); end
在matlab中输入这行代码,也可以运行:
>> hog = cv.HOGDescriptor();