face and eye detection crop
조회 수: 5 (최근 30일)
이전 댓글 표시
I detect the face using function available in computer vision system toolbox bbox = step(faceDetector, I);
I insert the box for detected face imageOut = step(boxInserter, I, uint8(bbox));
As a result, Some image has two or three boxes at the target subject. For example, I use this to detect the face, and some of the image have two box that detect the face in one image.
Crop Icrop = imcrop(I,bbox);
The problem is when I want to crop the detected face, it is error due to multiple bbox appear in the image.
How to solve this problem?
Thanks
댓글 수: 1
Shadman Sakib Khan
2016년 12월 11일
As far I know imcrop function can only crop using the parameter (x,y ,width, height). But in your bbox there are four corner position of the polygon. That's why the error occurs. But if you already solve the problem, can you please give me the solution of cropping an image using four corner point.
답변 (1개)
Tohru Kikawada
2017년 1월 13일
You can use cellfun for processing multiple ROIs as follows:
%%Create a detector object.
faceDetector = vision.CascadeObjectDetector;
%%Read input image.
I = imread('visionteam.jpg');
%%Detect faces.
bboxes = step(faceDetector, I);
%%Convert bboxes to cell arrays
bboxesCell = mat2cell(bboxes,ones(size(bboxes,1),1),size(bboxes,2));
%%Crop detected faces.
facesCropped = cellfun(@(x)imcrop(I,x),bboxesCell,'UniformOutput',false)
%%Display a cropped image
imshow(facesCropped{1});
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!