【问题标题】:Mapping bounding box to the original image in Matlab在 Matlab 中将边界框映射到原始图像
【发布时间】:2015-07-12 18:18:28
【问题描述】:

我有一个实时皮肤检测算法,它在皮肤区域周围提供一个边界框,带有来自原始图像的矩形('Position',bb,'EdgeColor','r','LineWidth',2)。我希望先使用代码从原始图像中检测皮肤区域,然后再使用 Viola Jones 从裁剪的皮肤区域中检测面部区域。我想知道在我裁剪皮肤区域然后使用人脸检测算法检测人脸后,如何将人脸的边界框映射到原始图像。

function cameraon_Callback(hObject, eventdata, handles)
% hObject    handle to cameraon (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global video;
global videoFrame;
axes(handles.axes1);
video = videoinput('winvideo',1,'YUY2_320x240');
set(video,'ReturnedColorSpace','rgb');
handles.video=video;
triggerconfig(video,'manual');
video.FramesPerTrigger = 1;
guidata(hObject,handles);
faceDetector=vision.CascadeObjectDetector('FrontalFaceCART');
faceDetector.MinSize=[20 20];
faceDetector.MergeThreshold = 20;
videoFrame=getsnapshot(video);
bbox=step(faceDetector,videoFrame);
 if numel(bbox) == 0
    errordlg('Face not detected. Please try again.');
    set(handles.cameraon,'String','Start Camera')
    stop(video);
    delete(video);
    clear;
else
     axes(handles.axes1);
     start(video);
end
while(true)
    frame=getsnapshot(video);
%Detect faces.
data = frame;% this is to read a image from data base. just put any image name u want to give make sure its placed in bin
diff_im = imsubtract(data(:,:,1), rgb2gray(data)); % deleting gray scale pixels from image
diff_im = medfilt2(diff_im, [3 3]); %applying filter one 
diff_im = imadjust(diff_im); % adjust image function to fill small holes (check all the function's functionality to have idea of whats going on)
level = graythresh(diff_im);% extract level value
bw = im2bw(diff_im,level);
BW5 = imfill(bw,'holes');
bw6 = bwlabel(BW5, 8);
stats = regionprops(bw6,['basic']);%basic mohem nist
measurements = regionprops(bw6, 'boundingbox');
BB1=struct2cell(measurements);
BB2=cell2mat(BB1);
a = BB2(1);
b = BB2(2);
c = BB2(3);
d = BB2(4);
[N,M]=size(stats);
if (bw==0)% check if there is no skin color then exit
        break;
else
     tmp = stats(1);
for i = 2 : N % checking for biggest hole to mark it as face 
      if stats(i).Area > tmp.Area
        tmp = stats(i);
      end
 end
bb = tmp.BoundingBox; % applying identification square to mark skin color region
bc = tmp.Centroid;
   videoFrame=getsnapshot(video);

这是我无法将边界框放回原始图像的地方。

   skinImage    = imcrop(videoFrame,bb(1,:));
    bbox = step(faceDetector,skinImage);
  bbox(1,1:2) = bbox(1,1:2) + bb(1,1:2);
      videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face'); 
    cla;
    imshow(videoOut,[]);
    drawnow;
    pause(0.0001);
  end
  end
  guidata(hObject,handles);

我想将我从人脸检测器获得的矩形放到图像中裁剪图像的原始位置的全尺寸图像上。

【问题讨论】:

    标签: matlab matlab-cvst bounding-box


    【解决方案1】:

    您只需将裁剪区域左上角的坐标添加到检测到的边界框的左上角即可。

    另外,在最新版的 MATLAB 中vision.CascadeObjectDetector 支持传入要检测对象的感兴趣区域,这样就不需要裁剪了。然后它会为你调整坐标。查看vision.CascadeObjectDetectorstep() 方法的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-14
      • 2014-05-01
      • 2015-04-04
      • 2020-05-03
      • 2021-01-26
      • 2015-05-14
      相关资源
      最近更新 更多