How to create a bounding box for multiple objects of interest

Hello Everyone,
I'm working on a project where my goal is to detect and recognize playing cards, and I'm having trouble creating bounding boxes and extracting them to compare against a template image. For right now, I'm just trying to create a bounding box for three separate cards in an image, although ideally I'd like to for just the corners of the cards. But while creating the bounding boxes I can only get it to work with one of the three cards in my image. I'll supply my code and image, and if anyone could help me any I would greatly appreciate it. For right now it is only working with the first card.
Ryan
*HERE IS MY CODE***** this is working to create the bounding box for one card. How can I for all three cards? %J is a binary image that's already been processed and using the canny edge detector.
J = Edge;
%For TEST IMAGE
imshow(J)
[B,L] = bwboundaries(J, 'noholes');
figure; imshow(J); hold on;
for k = 1;length(B),
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
end

 Réponse acceptée

for k = 1;length(B), needs ":" instead of ";"
for k = 1:length(B)

8 commentaires

wow, yes I was making a simple mistake with that. Only, now this is creating a bounding box for every object in my image. Do you have any advice on how I could create the bounding box for only the top left corners of the cards, that being the Jack, four, and nine along with their suits? If I can do this, I believe I should be able to use the matrix in that bounding box to compare to a template image to determine a match. But thank you, that helped too
discard all but the 3 largest areas. For example, bwareafilt
Thank you. I was actually just trying something like that using regionprops. I'm relatively new to Matlab, so I'm having a tough time figuring everything out, but this is helping me get on the right track. Thank you
regionprops is fine for the task, and if you are already using regionprops for something else then you might as well use it for producing the information used to determine which blobs you want to pay attention to. bwareafilt() is pretty new.
Ryan
Ryan le 5 Oct 2015
Modifié(e) : Ryan le 5 Oct 2015
I'm really just kind of experimenting with everything to see what will work best, so I'll try playing around with both. I haven't quite got it yet, but I'm sure I will.
Once I get this done, my plan was to use the properties of the bounding box of each card, and rotate each of them so that they are in an upright position. Once I got that done, I then planned to create a matrix of the upper left corner of the card to compare to a template, and hopefully determine matches. Does this all sound feasible to you? I'd hate to spend so much time trying to do this, then find out that won't even work..
Again, thank you so much for your help.
You might be more interested in the regionprops Orientation of the blobs you identified as the outline of the cards. That and a minor calculation should give you the rotation angle you would apply to the subimage.
Yea that's what I was I thinking. Even though I'm not quite at that point yet, do you have any advice for doing that in real time. I'm actually grabbing each and every frame from my video and processing the frames continuously. I don't think it would be too hard with a set image, but with varying distances and angles, I imagine this is going to be a difficult problem to solve.
It should still be reasonably fast.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by