How to draw centroid that include the value inside bounding box?

1 回表示 (過去 30 日間)
MOHAMAD AFIF
MOHAMAD AFIF 2015 年 2 月 9 日
コメント済み: MOHAMAD AFIF 2015 年 2 月 12 日
Hello, I want to ask for a little help. I'm writing a coding here on face tracking. But I dont know how to draw the centroid which also include the value inside the bounding box. Here's the coding:
clc
clear
%Create a detector object.
faceDetector = vision.CascadeObjectDetector;
%Read input image from Lenovo EasyCamera
obj = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240');
set(obj,'ReturnedColorSpace','rgb');
%Preview(obj)
figure('menubar','none','tag','webcam');
while(true)
frame=step(obj);
%Detect faces.
bboxes = step(faceDetector,frame);
%Annotate detected faces.
IFaces = insertObjectAnnotation(frame,'rectangle',bboxes,'ME');
imshow(IFaces,'border','tight')
f=findobj('tag','webcam');
if(isempty(f))
close(gcf)
break
end
pause(0.05)
end
%closepreview(obj)
release(obj)

回答 (2 件)

Erik S.
Erik S. 2015 年 2 月 9 日
Hi
Use the vision.BlobAnalysis method. It returns both bounding box and centroid.
  1 件のコメント
Image Analyst
Image Analyst 2015 年 2 月 9 日
MOHAMAD's "Answer" moved here since it's not an Answer to the original question:
If I'm using vision.CascadeObjectDetector, can it be done too? Thank you for your help Erik S. :)

サインインしてコメントする。


Dima Lisin
Dima Lisin 2015 年 2 月 9 日
Hi Mohamad,
vision.CascadeObjectDetector gives you bounding boxes of the form [x, y, width, height]. You can compute the centers of the bounding boxes as follows centers = bboxes(:, 1:2) + bboxes(:, 3:4) / 2. Then you can use the insertMarker function to mark the centers in your image.
  4 件のコメント
MOHAMAD AFIF
MOHAMAD AFIF 2015 年 2 月 11 日
I have try it, but still the bounding box doesn't show the value of the centroid
MOHAMAD AFIF
MOHAMAD AFIF 2015 年 2 月 12 日
After try and try and make a lots of troubleshoot in the coding, I've get what I want. Thank you Dima Lisin for your help and guide. It really work!! :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by