Borrar filtros
Borrar filtros

How to draw a rectangle around the characters of a text

4 visualizaciones (últimos 30 días)
raha boolat
raha boolat el 14 de Jul. de 2021
Editada: KSSV el 14 de Jul. de 2021
I want to draw a rectangle around the letters so that each letter is inside a rectangle. I wrote this code, but it considers the letters of the dots as two parts, and draws a box around the dot and the character of each.
function obj_det(img_name)
f=imread (img_name);
if (size(f,3) >1)
f=rgb2gray(f);
f_bw=~im2bw(f,graythresh(f));
else
f_bw=~im2bw(f,graythresh(f));
end
f_bw=imfill(f_bw,'holes');
s=bwconncomp(f_bw);
imshow(f);
for i=1:s.NumObjects
ind=s.PixelIdxList{i};
[r,c]=ind2sub(size(f),ind);
min_r=min(r,[],1);
max_r=max(r,[],1);
min_c=min(c,[],1);
max_c=max(c,[],1);
hy=max_r - min_r;
hx=max_c - min_c;
rectangle('position',[min_c,min_r,hx,hy],'EdgeColor','r');
end
end

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by