フィルターのクリア

How to draw a rectangle around the characters of a text

4 ビュー (過去 30 日間)
raha boolat
raha boolat 2021 年 7 月 14 日
編集済み: KSSV 2021 年 7 月 14 日
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

回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by