how to connect the adjacent lower edges of each bounding box

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Rik
Rik il 17 Ago 2019
You have the coordinates right? Then what exactly is your issue?
praveen rai
praveen rai il 17 Ago 2019
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

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 17 Ago 2019
Modificato: Image Analyst il 17 Ago 2019
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 Commento
praveen rai
praveen rai il 17 Ago 2019
Modificato: praveen rai il 17 Ago 2019
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

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by