伙计们,我得到了这段经过裁剪的图像试图找到虹膜的代码,这是真实程序代码的有效片段:
clc
clear all
path = './vid/primaprovaedited/Luca Neutro.avi';
tic
video = VideoReader(path);
sourceImg = readFrame(video);
sourceImgL = insertText(sourceImg,[0,0],'Draw a rectangle around the eye displayed to the LEFT and press ENTER', 'FontSize', 40, 'BoxColor', 'red');
h = figure;
imshow(sourceImgL);
r1 = drawrectangle('Label','Eye to the left','Color',[1 0 0],'Position',[500,500,500,500]);
pause;
leftEyeRectange = r1.Position;
sourceImg = readFrame(video);
sourceImg = imcrop(sourceImg, leftEyeRectange);
%sourceImg = imresize(sourceImg, 0.5); % Reduce img size for permormance issue
r=0.8;
low=[0 0.05 0.025 0.020 0.010 0.05 0.04];
for i=1:size(low,2)
r=r+low(i);
[centers, radii] = imfindcircles(sourceImg, [40 60],'ObjectPolarity','dark','Sensitivity', r);
if ~isempty(centers)
center = centers(1,:);
radius = radii(1,:);
sourceImg = insertShape(sourceImg, 'Circle', [center(1,1), center(1,2), radius(1)], 'LineWidth',2, 'Color','red');
break;
end
end
figure;
imshow(sourceImg);
imdistline;
toc
它可以正常工作,但是要花很多时间,主要是因为传递给imfindcircle函数的img太大。因此,我尝试使其运行更快,以减少和缩放输入img(现在,裁剪区域为250x250,并且尺寸减小了):
clc
clear all
path = './vid/primaprovaedited/Luca Neutro.avi';
tic
video = VideoReader(path);
sourceImg = readFrame(video);
sourceImgL = insertText(sourceImg,[0,0],'Draw a rectangle around the eye displayed to the LEFT and press ENTER', 'FontSize', 40, 'BoxColor', 'red');
h = figure;
imshow(sourceImgL);
r1 = drawrectangle('Label','Eye to the left','Color',[1 0 0],'Position',[500,500,250,250]); %smaller cropped img
pause;
leftEyeRectange = r1.Position;
sourceImg = readFrame(video);
sourceImg = imcrop(sourceImg, leftEyeRectange);
sourceImg = imresize(sourceImg, 0.5); % Reduce img size for permormance issue
r=0.8;
low=[0 0.05 0.025 0.020 0.010 0.05 0.04];
for i=1:size(low,2)
r=r+low(i);
[centers, radii] = imfindcircles(sourceImg, [20 40],'ObjectPolarity','dark','Sensitivity', r); %reduced radius
if ~isempty(centers)
center = centers(1,:);
radius = radii(1,:);
sourceImg = insertShape(sourceImg, 'Circle', [center(1,1), center(1,2), radius(1)], 'LineWidth',2, 'Color','red');
break;
end
end
figure;
imshow(sourceImg);
imdistline;
toc
但是,即使以为img仍然清晰(我可以使用上一个imshow查看它),并且输入了正确的半径范围(使用上一个imdistline计算),但是仍然没有圆或随机的圆。
能否请您帮助我了解我在做什么错?我认为这是范围的问题,但我尝试了所有可能的选择,但未获得任何良好的结果。