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

Detect Text direction #9

Closed
tuan-nng opened this issue Jun 20, 2020 · 10 comments · Fixed by #137
Closed

Detect Text direction #9

tuan-nng opened this issue Jun 20, 2020 · 10 comments · Fixed by #137

Comments

@tuan-nng
Copy link

I have an image which is rotated 90 degrees. The program rotates it back 90 degrees but in wrong direction - text is on reverse direction.

Do you have any idea how to fix this?

@apdullahyayik
Copy link

Angle is correct but with 50 percent. It should be fixed

@sbrunner
Copy link
Owner

Can you provide the failing image?

@kbrajwani
Copy link

kbrajwani commented Oct 9, 2020

@sbrunner
in my case if image angle is 80 it will rotate more 10 so angle will become 90. same for 180 and 270 degrees.
image

import numpy as np
from skimage import io
from skimage.transform import rotate
from skimage.color import rgb2gray
import cv2
from deskew import determine_skew

filename = 'Acord25.png'
image_orig = cv2.imread(filename)
image_orig = rgb2gray(image_orig)
image_orig1 = rotate(image_orig, 90,resize = True,cval=1)*255  ## i have done custom rotation for check code
image_orig1 = image_orig1.astype(np.uint8)
image_orig1.shape

image = rgb2gray(image_orig1)
angle = determine_skew(image)
print(angle)
if angle != 0:
  image_orig1 = rotate(image_orig1, angle, resize=True,cval=1) * 255

actual angle is 90 but it gives me 0.0 .
if my actual angle is 80 then it gives me 10.0 which will make my image rotation at 90 degree .

@kbrajwani
Copy link

hey @sbrunner can you help me in this.

@sbrunner
in my case if image angle is 80 it will rotate more 10 so angle will become 90. same for 180 and 270 degrees.
image

import numpy as np
from skimage import io
from skimage.transform import rotate
from skimage.color import rgb2gray
import cv2
from deskew import determine_skew

filename = 'Acord25.png'
image_orig = cv2.imread(filename)
image_orig = rgb2gray(image_orig)
image_orig1 = rotate(image_orig, 90,resize = True,cval=1)*255  ## i have done custom rotation for check code
image_orig1 = image_orig1.astype(np.uint8)
image_orig1.shape

image = rgb2gray(image_orig1)
angle = determine_skew(image)
print(angle)
if angle != 0:
  image_orig1 = rotate(image_orig1, angle, resize=True,cval=1) * 255

actual angle is 90 but it gives me 0.0 .
if my actual angle is 80 then it gives me 10.0 which will make my image rotation at 90 degree .

@Jovi-droid
Copy link

angle += 90 if angle < -88 else 0

@llermaly
Copy link

Same problem here. I'm trying with ID's

if the text is facing to the right (rotated 90°) then works good, but if its facing to the left then it rotates upside down.

girado2
girado

@sbrunner
Copy link
Owner

deskew didn't detect the text direction, you can use tesseract --psm 0 to get the right orientation :-)

@shubham303
Copy link

angle += 90 if angle < -88 else 0

I used this condition before rotating, now it works fine. all the images are correctly rotated. But I did not understand the logic behind it.

@varun-affinsys
Copy link

angle += 90 if angle < -88 else 0

I used this condition before rotating, now it works fine. all the images are correctly rotated. But I did not understand the logic behind it.

Can u send ur final code.

@flash0729
Copy link

        start = time.time()
        filePath = path + '/' + str(f)
        image = cv2.imread(filePath)
        grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        angle = determine_skew(grayscale)
        angle += 90 if angle < -88 else 0
        print('calculated=' + str(angle) + ', file=' + str(f))
        rotated = rotate(image, angle, (0, 0, 0))
        end = time.time()
        print('time' + str(end - start))
        cv2.imwrite('res/rotated-' + str(f), rotated)

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

Successfully merging a pull request may close this issue.

9 participants