centroid of a bounding box

23 visualizaciones (últimos 30 días)
Jose Rodriguez
Jose Rodriguez el 24 de Abr. de 2019
im working on a school project in which the camera takes a picture of you and detects mouth, nose, and eyes. what im having problems with is getting the to detect all three features and the centroid of the bounding boxes on the same image. i also want to be able to calculate the distance between the centroids of the bounding boxes. im also fairly new to matlab so im sure theres some errors here.
faceDetector = vision.CascadeObjectDetector;
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[0 255 255]);
cam = webcam(1)
%preview(cam)
%pause(5)
%closepreview
img = snapshot(cam);%Read the input image
img1 = rgb2gray(img);
BW = edge(img1,'Canny');%Edge detection
threshold = 1; % custom threshold value
BW1 = BW < threshold; % Creates white image with black edges
%imshow(BW1);
%Centroid Try1
BW2 = imcomplement(BW1);
%imshow(BW2)
s = regionprops(BW2,'centroid');
centroids = cat(1,s.Centroid);
x0 = centroids(1,1),
y0 = centroids(1,2)
imshow(img)
hold on
plot(centroids(:,1),centroids(:,2),'r*')
hold off
%To detect Mouth
MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',100);
BB = step(MouthDetect,img1);
figure,
imshow(img1); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','k');
end
%%
%to detect nose
%NoseDetect = vision.CascadeObjectDetector('Nose');
%BB = step(NoseDetect,img);
%rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','k');
%hold on
%To detect Eyes
%EyeDetect = vision.CascadeObjectDetector('EyePairBig');
%BB = step(EyeDetect,img);
%rectangle('Position',BB,'LineWidth',4,'Line0Style','-','EdgeColor','k');
%hold on
%distance line
%h = imdistline;
%fcn = makeConstrainToRectFcn('imline',get(gca,'XLim'),get(gca,'YLim'));
%setDragConstraintFcn(h,fcn);
closePreview(cam)
clear('cam')
clear camObject;

Respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by