detecting rectangle in real images

Hey all,
I want to detect and track rectangle pattern . these pattern I want to set on object which moving and captured using webcam.
So, the image will include real-world scene also - not only the pattern.
example of pattern:
I want to be able to detect the 4 corners of the white rectangle.
what about if I have black rectangle?
Thanks in advance

5 commentaires

Image Analyst
Image Analyst le 17 Juin 2014
This does not look like a real world image. It looks like a computer graphics image. Please attach the real world images.
shdrone
shdrone le 17 Juin 2014
Modifié(e) : shdrone le 17 Juin 2014
yes I know- I want to print this pattern and put it on moving object (for example : human) and the camera capture image including the pattern and more.
I wrote this note because I found a code that can detect this rectangle when you pass to it the pattern image only - and detect another objects in the image that isn't a rectangle when you pass to it real world image.
Image Analyst
Image Analyst le 17 Juin 2014
Okay, so....after that explanation . . . my comment remains the same.
shdrone
shdrone le 17 Juin 2014
ok - no problem.
here's an image :
thanks
shdrone
shdrone le 18 Juin 2014
Do you have a solution for this image?

Connectez-vous pour commenter.

Réponses (4)

Image Analyst
Image Analyst le 18 Juin 2014

1 vote

Does the clutter have to be in the background? It requires a more time consuming and complicated algorithm. I'd take the green channel, threshold for dark things. Find objects in a certain size range with a certain Euler number. Then call bwboundaries() and take the inner boundary.

2 commentaires

shdrone
shdrone le 18 Juin 2014
Hi,
I think it's working good (I tested some images).
my question : can this code give me the coordinates of the 4 corners of the rectangle or just the Centroid?
Thanks for your help
Image Analyst
Image Analyst le 21 Mai 2016
No it can't (and that's my code so I should know). But I have an updated demo, attached, that can.

Connectez-vous pour commenter.

Spandan Tiwari
Spandan Tiwari le 19 Juin 2014

0 votes

If your rectangle does not change orientation, you can try using normxcorr2 (in Image Processing Toolbox) with the rectangle as the template. If changes in orientation are possible you may have to use more than one templates.
Elizabeth Rocha
Elizabeth Rocha le 21 Mai 2016
Modifié(e) : DGM le 14 Fév 2023
my code for this is :
imagen=imread('img18.jpg');
recorte=imagen(112:221,218:274);
recorte2=imagen(261:309,233:317);
recorte=im2bw(recorte);
recorte2=im2bw(recorte2);
subplot(1,3,1),imshow(imagen)
rectangle('position',[218,112,56,109]);
% ---this is for captured using webcam
rectangle('position',[233,261,84,48]);
subplot(1,3,2),imshow(recorte)
subplot(1,3,3),imshow(recorte2)
if recorte==true
x=1
else
x=0
end
if recorte2==true
y=1
else
y=0
end

3 commentaires

Ayush singhal
Ayush singhal le 20 Avr 2021
Can you tell how to generate rectangular stripes with fixed period and width of the stripes should be half of period.
Image Analyst
Image Analyst le 20 Avr 2021
@Ayush singhal, try rectpuls() if you have the Signal Processing Toolbox. Otherwise create one pulse using ones() and zeros() and then replicate it as many times as you want with repmat.
Ayush singhal
Ayush singhal le 21 Avr 2021
But I need stripes as a image not like pulses. stripes like black white black white black white.....
I think this needs image processing tool.

Connectez-vous pour commenter.

Matt J
Matt J le 20 Avr 2021
Modifié(e) : Matt J le 20 Avr 2021
This works for the one given image. I would need more examples to see if it's a reliable solution. It uses the FEX contribution pgonCorners which must be Downloaded.
load Image
C=bwpropfilt(all(Image<50,3),'ConvexArea',1);
D=bwareafilt( bwconvhull(C)-C>0.5 ,1);
xy=fliplr(pgonCorners(D,4)); %corner coordinates
imshow(Image);
hold on
scatter(xy(:,1), xy(:,2),30,'r','filled')
hold off

Question posée :

le 17 Juin 2014

Modifié(e) :

DGM
le 14 Fév 2023

Community Treasure Hunt

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

Start Hunting!

Translated by