MATLAB: I need to crop an image after face detection but i get an error.

Computer Vision Toolboxsend a solution

clc;
vid = videoinput('winvideo',1);
preview(vid);
start(vid);
set(vid, 'ReturnedColorSpace', 'RGB');
for frame =1:2
% your function goes here
thisFrame = getsnapshot(vid);
if frame == 1
a = thisFrame;
else
b = thisFrame;
end
pause(1);
end
faceDetector = vision.CascadeObjectDetector();
% Read a video frame and run the detector.
bbox = step(faceDetector, a);
IFaces = insertObjectAnnotation(a, 'rectangle', bbox, 'face');
%disp(IFaces);
% Draw the returned bounding box around the detected face.
%boxInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[255 255 0]);
%videoOut = step(boxInserter,a,bbox);
figure, imshow(IFaces), title('Detected face');
bbox_face = zeros(size(bbox_body));
for i=1:length(bbox)
Icrop = imcrop(a,bbox(1,i));
bbox = step(faceDetector,Icrop);
bbox_face(i,:) = bbox + [bbox(1,1:2)-1 0 0];
end
I_faces2 = step(shapeInserter, I, int32(bbox_face));
figure, imshow(I_faces2);
Icrop = imcrop(a,bbox(1,:));
figure;imshow(Icrop);
Icrop = imcrop(a,bbox(2,:));
figure;imshow(Icrop);
Icrop = imcrop(a,bbox(3,:));
figure;imshow(Icrop);
Icrop = imcrop(a,bbox(4,:));
figure;imshow(Icrop);
and the error is
Error using imshow>preParseInputs (line 457)
The syntax IMSHOW(I,N) has been removed.
Error in imshow (line 215)
varargin_translated = preParseInputs(varargin{:});
Error in imcrop>parseInputs (line 241)
imshow(a,cm);
Error in imcrop (line 94)
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] =
parseInputs(varargin{:});
Error in facedetection1 (line 27)
Icrop = imcrop(a,bbox(1,i));
please send some solution

Best Answer

bbox(1,i) is a scalar. There are no (remaining) syntaxes for imcrop that allow you to supply a scalar as the second argument.
If you are thinking of it as cropping off each of four edges in turn, then in each call you still need to supply 4-element rectangle that describes a box to clip at.
Related Question