# detecting rectangle in real images

33 views (last 30 days)
shdrone on 17 Jun 2014
Commented: Ayush singhal on 21 Apr 2021
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?
shdrone on 18 Jun 2014
Do you have a solution for this image?

Image Analyst on 18 Jun 2014
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 CommentsShowHide 1 older comment
Image Analyst on 21 May 2016
No it can't (and that's my code so I should know). But I have an updated demo, attached, that can.

Spandan Tiwari on 19 Jun 2014
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 on 21 May 2016
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
Ayush singhal on 21 Apr 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.

Matt J on 20 Apr 2021
Edited: Matt J on 20 Apr 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.
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

### Categories

Find more on Semantic Segmentation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!