Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some bounding boxes are twisted in a way where they don't properly represent the text #15

Open
cjnolet opened this issue Jan 26, 2017 · 2 comments

Comments

@cjnolet
Copy link

cjnolet commented Jan 26, 2017

In a few cases, it almost appears the bottom left and the top right boxes are flipped causing the bounding box to almost appear as two triangles that are touching at one of the points rather than a single rectangle. Not exactly sure what is causing this

@MansourTrabelsi
Copy link

help me please , i have this error
Traceback (most recent call last):
File "gen.py", line 19, in
from synthgen import *
File "/home/mansour/SynthText/synthgen.py", line 20, in
import text_utils as tu
File "/home/mansour/SynthText/text_utils.py", line 12, in
from pygame import freetype
ImportError: cannot import name freetype

@shubham303
Copy link

I solved bounding box twist problem by using below function

def order_points(pts):
	# sort the points based on their x-coordinates
	xSorted = pts[np.argsort(pts[:, 0]), :]
	# grab the left-most and right-most points from the sorted
	# x-roodinate points
	leftMost = xSorted[:2, :]
	rightMost = xSorted[2:, :]
	# now, sort the left-most coordinates according to their
	# y-coordinates so we can grab the top-left and bottom-left
	# points, respectively
	leftMost = leftMost[np.argsort(leftMost[:, 1]), :]
	(tl, bl) = leftMost
	
	rightMost = rightMost[np.argsort(rightMost[:, 1]), :]
	tr, br = rightMost
	
	x1, y1 = bl
	x2, y2 = br
	w1 =  math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	
	x1, y1 = tl
	x2, y2 = tr
	w2 =  math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	#width of box
	w = max(w1, w2)
	
	x1, y1 = tl
	x2, y2 = bl
	h1 = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	
	x1, y1 = tr
	x2, y2 = br
	h2 = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	h=max(h1, h2)  # height of box
	
	return np.array([tl, tr, br, bl], dtype="float32"), int(w) , int(h)

This function, given a bounding box returns, coordinates in clockwise order starting from top left, also it returns width and height of bounding box

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants