在matlab中编译为c代码imcrop无法运行。 有没有其他方法可以抑制?
我正在使用Matlab2016a。以下是代码段:
function signal = detectFatigue(im)
% Create a detector object
faceDetector = vision.CascadeObjectDetector('ClassificationModel','FrontalFaceLBP','MinSize',[100 100]);
faceDetectorLeye = vision.CascadeObjectDetector('EyePairBig');
% Detect faces
bbox = step(faceDetector, im);
if ~isempty(bbox);
bbox = bbox(1,1:4);
Ic = imcrop(im,bbox);
bboxeye = step(faceDetectorLeye, Ic);
if ~isempty(bboxeye);
bboxeye = bboxeye(1,1:4);
Eeye = imcrop(Ic,bboxeye);
[~, nce, ~ ] = size(Eeye);
% Divide into two parts
Leye = Eeye(:,1:round(nce/2),:);
Reye = Eeye(:,round(nce/2+1):end,:);
% make grascale
Leye = rgb2gray(Leye);
Reye = rgb2gray(Reye);
Leye = filterim(Leye);
Reye = filterim(Reye);
lroi = [ 12 5 30 16 ];
rroi = [ 18 5 30 16 ];
Leyeroi = imcrop(Leye,lroi);
Reyeroi = imcrop(Reye,rroi);
[lc, ~ ] = findcircle(Leyeroi);
[rc, ~ ] = findcircle(Reyeroi);
if isempty(lc) && isempty(rc)
signal = 1;
else
signal = 0;
end
end
end
function Leye=filterim(Leye)
se = strel('disk',2,4);
% dilate graysacle
Leye = imdilate(Leye,se);
% erode grayscale
Leye = imerode(Leye,se);
Leye = imadjust(Leye);
Leye = imcomplement(Leye);
Leye = im2bw(Leye,0.95);
Leye = imresize(Leye,[30 60]);
function [c, r] = findcircle(Leyeroi)
[c ,r ] = imfindcircles(Leyeroi,[5 9],'ObjectPolarity','bright','Sensitivity',0.95);
[rm,id] = max(r);
r = rm;
c = c(id,:);
if ~isempty(c)
c(1) = c(1) + 15;
c(2) = c(2) + 7;
end
编辑: fullcode
function testdetectFatigue()
vid=webcam(1);
for loop=1:10
im=snapshot(vid);
detectFatigue(im);
end
并测试下面的detectFatigue.m是函数
@JsonUnwrap