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

understanding render_curved #120

Closed
rohitsaluja22 opened this issue Jul 12, 2018 · 1 comment
Closed

understanding render_curved #120

rohitsaluja22 opened this issue Jul 12, 2018 · 1 comment

Comments

@rohitsaluja22
Copy link

rohitsaluja22 commented Jul 12, 2018

Hey I am trying to understand function "def render_curved(self,font,word_text):" defined in text_utils.

I took a font "Shobhika" https://github.com/Sandhi-IITBombay/Shobhika
loaded it with the size of 30

font_file
'/home/rohit/.local/share/fonts/Shobhika-Regular.otf'
font = pygame.freetype.Font(font_file,30)
font
Font('/home/rohit/.local/share/fonts/Shobhika-Regular.otf')

Got a surface of size 134X159 accordingly for word_text = "hello":-

word_text = "hello"
wl = len(word_text) # = 5
lspace = font.get_sized_height() + 1
lspace
53
lbound = font.get_rect(word_text)
lbound
<rect(0, 23, 67, 23)>
fsize = (round(2lbound.width), round(3lspace))
fsize
(134, 159)
surf = pygame.Surface(fsize, pygame.SRCALPHA, 32)
surf
<Surface(134x159x32 SW)>

Got the following curve and rots as samples:-

mid_idx = wl//2
BS = self.baselinestate.get_sample()
curve = [BS'curve' for i in range(wl)]
curve[mid_idx] = -np.sum(curve) / (wl-1)
rots = [-int(math.degrees(math.atan(BS'diff'/(font.size/2)))) for i in range(wl)]
curve
[-1.75256073377731, -0.4381401834443275, 1.0953504586108187, -0.4381401834443275, -1.75256073377731]
rots
[-6, -3, 0, 3, 6]

The following code of updating rect.centerx is clear:-

bbs = []
rect = font.get_rect(word_text)
rect
<rect(0, 23, 67, 23)>
surf.get_rect().centerx
67
rect.centerx = surf.get_rect().centerx
rect
<rect(34, 23, 67, 23)>

It seems like (0,23) was the left bottom point WITH CO-ORDINATE SYSTM OF IMAGE X GOING RIGHT Y GOING DOWN, which got shifted to (34,23) i.e. centre(67) - rendered_word_text_width//2(i.e. 67//2 = 33) = 34

Now, the problem is in understanding the update of rect.centery:-

rect.centery
34
surf.get_rect().centery
79
rect.height
23
rect
<rect(34, 23, 67, 23)>
rect.centery = surf.get_rect().centery + rect.height
rect
<rect(34, 91, 67, 23)>

centery of rect is moved to 79 + 23 i.e 102, so the bottom point should be 102 + 23//2 = 113 but what we get is 91. Can you explain?

Also in function place_text: why is loc, which is the random choice of x and y coordinates from the collision-free location in the mask, reversed as loc[::-1] while updating bounding boxes bbs[i] = move_bb(bbs[i],loc[::-1]) ?

@ankush-me
Copy link
Owner

ankush-me commented Sep 12, 2018

@rohitsaluja22:
(1) the bottom point should be (center - h/2) = 102 - 23/2 = 91 -- which is what you get.
(2) Pygame surface is transposed wrt opencv / normal image conventions, hence, we need to reverse the coordinates.

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

No branches or pull requests

2 participants