-
Notifications
You must be signed in to change notification settings - Fork 16
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
Output image is incorrectly clipped when rotation angle is 90 degrees. #2
Comments
Well... Let me see what I can do about properly rotating the image from landscape to portrait modes. Yes, the behaviour you're experiencing is because the rotate method is usually expected to work with values in -10 to +10 degrees range, so it preserves the original width/height of the input image, in your case - landscape mode dimensions. I need to point out one more issue - the images you provided are not really fitting for this deskew method, I was aiming to build this for text-based pages, like PDF scans of documents and etc. Nevertheless I'll try to fix the rotation problem that you described. |
JPLeoRx - Thanks for your interest. I completely understand that deskew() isn't intended for graphic images. I'm working on a driver for my Fujitsu ScanSnap document scanner. It's a great piece of hardware, but Fujitsu abandoned the Mac driver several years ago. The hardware works well, so I've been working on a driver of my own. Everything is implemented except deskewing. I've tested 4 or 5 different deskew implementations, and yours is the clear winner. It's faster than most, generates clean output documents, and usually produces images that are aligned within a degree or so. I scan a variety of documents with varying amounts of text and images. Pages are intermixed, and occasionally include a page that's very graphics-heavy. It's not practical to selectively turn deskew on and off for individual pages. Frankly, I'm impressed your code it does so well on my test documents. The image I'm using here is the most severe test of all. The only hiccup I've seen so far is this bug that causes data loss. thanks again! |
When testing with your original image I cannot reproduce the 90 degree skew angle calculation, on my local machine opencv estimates the angle of your image to be 0.93. But regarding the rotation issue - I can reference you to another project of mine, https://github.com/JPLeoRX/tekleo-common-utils, this is a somewhat shared codebase for various commonly used methods. I've just added an OpenCV section into it. If you go to this script and look at I'll also update the original opencv-text-deskew project to use this shared library |
JPLeoRx - Thanks for your suggestions. It's strange that our two computers calculate such different angles. For the record, I'm using an up-to-date Mac with
Double-checking the versions of the underlying libraries:
If I make minor changes to the document (by saving it in a different format, for example), the calculated skew angle may be slightly different. But I always get results close to -90 degrees:
Thanks again for this code and for your help with making it better. |
Just fyi, here are some test text documents. They're probably a more realistic test of the deskew code. I printed a text page on paper in landscape mode. I rotated the scanned image into landscape mode and saved a copy. It's interesting that deskew computes a skew angle of (approximately) -90 degrees for both documents. I expect that one angle should be ~-90 degrees, and the other would be ~0 degrees. I hope they're useful to you. thanks! |
Imagine a document in landscape mode. It is wider than it is tall.
The document happens to have an image with many vertical lines. DeskewService.deskew() decides that the image is skewed by 90 degrees.
deskew() rotates the image by 90 degrees, producing a portrait image. Unfortunately, it writes this image to an output document in landscape mode.
Thus a portrait image is now clipped to the dimensions of a landscape document.
(I did some trial-and-error editing of GraphicsService.rotateImage() but didn't stumble upon a fix. I'm a complete newbie with openCv and PIL, so this should be no surprise.)
I attached the input and output images.
Please let me know how I can help! thanks
The text was updated successfully, but these errors were encountered: