如何将MATLAB中的detectMSERFeatures函数转换为C?

时间:2016-02-04 05:16:13

标签: matlab computer-vision matlab-cvst matlab-coder

我编写了一个计算机视觉代码,它使用MSER检测MATLAB中的功能。我使用内置的'detectMSERFeatures'函数来处理本地保存的视频。现在,我想用MATLAB Coder将它移植到C语言中。但是,MATLAB Coder不支持此功能。我附上了输出的截图。任何帮助将不胜感激。

http://i.stack.imgur.com/brYQT.png

我的代码如下:

function count = master
% Clear workspace and Initialize Frame count
clear all;
F=0;
count=0;
% 1.Input Video Object Handler Definition
inputVideo = vision.VideoFileReader('video.mp4');
videoPlayer = vision.VideoPlayer;

% 2.Cropping Height and Width of frame. Subject to convenient
%   adjustments according to the position of camera. Mainly using to
%   crop out street lights from the top of the frame.
height = floor(inputVideo.info().VideoSize(2)*0.7);
width = inputVideo.info().VideoSize(1);
crop = vision.ImagePadder(...
                        'SizeMethod','Output size', ...
                        'NumOutputRowsSource','Property', ...
                        'RowPaddingLocation','Top', ...
                        'NumOutputRows', height, ...
                        'NumOutputColumns', width);

% 3.Frame Conversion from True Colour to Grayscale
gray = vision.ColorSpaceConverter;
gray.Conversion = 'RGB to intensity';

% 4.Implementation on individual frames till the end of video.
while(~isDone(inputVideo))
% Current Frame number
F = F + 1;
%flag=0
% Current Frame
currentFrame = step(inputVideo);
% Crop
currentFrame = step(crop, currentFrame);
% Convert to Grayscale
currentFrame = step(gray, currentFrame);
% Threshold
currentFrame(currentFrame<0.7843) = 0;
% Detect MSER Regions
regions = detectMSERFeatures(currentFrame, ...
                            'RegionAreaRange', [800 3000], ...
                            'ThresholdDelta', 4);
% Check for 'big bright blob(s)', or high incoming beam
% and output detected blob count and corresponding frame
if(regions.Count >= 2 && regions.Count <=6)
    disp([regions.Count, F]);
    %flag=1;
    count= count+1;

end
% Port frame to player
step(videoPlayer,currentFrame);
end

%5.Release both player and video file instances
release(inputVideo);
release(videoPlayer);

我正在使用MATLAB R2013a。

1 个答案:

答案 0 :(得分:0)

解决这个问题的唯一方法是升级到更新版本的MATLAB。 R2013b版本中添加了detectMSERFeatures的代码生成支持。