how to extract the bounding box area as segmented object from video frame?...I have been trying imcrop but the rectangle cropped out is not as same as bbox rectangle.

I am using computer vision toolbox.. this is the code..Is there any other way of doing it??
please help..thankyou in advance!
crop=bbox(:,); % all bbox that hav objects
crop=transpose(crop); % bbox as crop in row major as for rectangles
num = size(crop,1);
for k = 1: num
crop(k,2)=crop(k,2)-crop(k,3); % ymin is required but ymax is in upper left corner
temp=crop(k,3); % swapping height and width as required in rectangle! crop(k,3)=crop(k,4); crop(k,4)=temp;
[Xtest,Ytest,itest,Rtest]=imcrop(image,crop(k,:));
imshow(itest);

 Réponse acceptée

I don't know what bbox is. Don't use image as the name of your image variable because it's the name of a built-in function. Simply crop like this:
croppedImage = imcrop(fullImage, [leftColumn, topRow, numberOfColumns, numberOfRows]);
You have to figure out how to get leftColumn, topRow, numberOfColumns, numberOfRows.

2 commentaires

Thankyou for the reply..actually m using computer vision system toolbox..After doing blol analysis I got bounding box for the object which is the vehicle in the frames.. This bbox is actually the same bounding box.This is the code..
hblob = vision.BlobAnalysis( ... 'CentroidOutputPort', false, ... 'AreaOutputPort', true, ... 'BoundingBoxOutputPort', true, ... 'OutputDataType', 'single', ... 'NumBlobsOutputPort', false, ... 'MinimumBlobAreaSource', 'Property', ... 'MinimumBlobArea', 250, ... 'MaximumBlobAreaSource', 'Property', ... 'MaximumBlobArea', 3600, ... 'FillValues', -1, ... 'MaximumCount', 80);
[area, bbox] = step(hblob, fg_image);
So the left column, toprow, no of columns, number of rows that you have told to find to use imcrop is sctually given by this bbox!
But still m not getting the segmented vehicle..The box is drwan correctly but not segmented via imcrop..I think the cordinates are not matching for bbox and imcrop..Please please help..
I don't know what step() does, but in all the MATLAB functions that I can think of when it wants a rectangle, it's [xStart, yStart, xSize, ySize]. Check with the documentation for step() - for example make sure it's not using row, column instead of x,y.

Connectez-vous pour commenter.

Plus de réponses (1)

It seems to work for me...The rectangle specification provided by the vision.BlobAnalysis object is the same as that required by imcrop.
im = padarray(strel('disk',100,0).getnhood,[50 25],'pre');
hblob = vision.BlobAnalysis;
[area,centroid,bbox] = step(hblob,im);
>> bbox
bbox =
26 51 201 201
out = imcrop(im,bbox);
imshow(out);

2 commentaires

running the same code giving me this error:
Error using ==> imageDisplayParsePVPairs at 121
Invalid input arguments.
Error in ==> imageDisplayParseInputs at 70 [common_args,specific_args] = imageDisplayParsePVPairs(varargin{:});
Error in ==> imshow at 199 [common_args,specific_args] = ...
Error in ==> imcrop>parseInputs at 248 imshow(a,cm);
Error in ==> imcrop at 94 [x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:});
I am using matlab R2011? which one you used?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by