In my project, it needs recognise the square marrker in the real time video input. In every frame,the square marker should be recoginzed stability.And the following codes was used to detected the square marker.however,it cause error in same frames,and i have try many methods but still useless.
gray_img = rgb2gray(img);
bw_img= im2bw(gray_img,0.35);
[B,L] = bwboundaries(bw_img,'noholes');
se1=strel('square',30);
L_erode=imerode(L,se1,'same');
stats =[regionprops(L_erode); regionprops(not(L_erode))];
A=[stats.Area];
idx=find(A==min(A(A~=0)));
the test image is here: