how to connect the adjacent lower edges of each bounding box

1 次查看(过去 30 天)
I have drawn a bounding box of rectangle shape on each character and save the all 4 point of all bounding box
Now I want to connect the lower edges of bounding box with each other
How to do it??
sample code for making bounding box and saving all 4 points of bounding box
I = imread('textlineImage.png');
I=im2bw(I);
I=imcomplement(I);
st=regionprops(I,'BoundingBox','Area');
allBB = zeros(length(st), 4);
for k = 1 : length(st)
thisBB = st(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor', 'r', 'LineWidth', 1)
allBB(k, :) = thisBB;
points are save in varibale allBB
Image is
234.jpg
  8 个评论
Rik
Rik 2019-8-17
You have the coordinates right? Then what exactly is your issue?
praveen rai
praveen rai 2019-8-17
ya I have 4 point values of rectangle box in variable allBB but which two points I have to take and how to plot for every line so that I can get spline that is the issue
I am unable to wirte these thing in loop

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2019-8-17
编辑:Image Analyst 2019-8-17
Use kmeans on the y values to identify boxes in one of the 5 lines that your image has.
[classIndexes, classCentroid] = kmeans(y, 5);
After that, you know which line each y is in then sort by x, then use spline. Something like (untested)
y = allBB(2:4:end);
[classIndexes, classCentroid] = kmeans(y, 5);
newXSamplePoints = 1 : size(yourImage, 2)
for k = 1 : 5
thisClass = classIndexes(k);
thesex = sort(x(thisClass), 'ascend');
% Fit the x to splines at every column in the image.
newY = spline(x, y, newXSamplePoints);
end
hold on;
plot(newXSamplePoints, newY, 'm-', 'LineWidth', 2)
  1 个评论
praveen rai
praveen rai 2019-8-17
编辑:praveen rai 2019-8-17
its showing the following error
Error using kmeans (line 247)
X must have more rows than the number of clusters.
Error in rawcode (line 25)
[classIndexes, classCentroid] = kmeans(y, 5);
allBB has value 208*4 double and y has 1*208 double

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by