deskew | Library used to deskew a scanned document | Computer Vision library
kandi X-RAY | deskew Summary
kandi X-RAY | deskew Summary
Note: Skew is measured in degrees. Deskewing is a process whereby skew is removed by rotating an image by the same amount as its skew but in the opposite direction. This results in a horizontally and vertically aligned image where the text runs across the page rather than at an angle. The return angle is between -45 and 45 degrees to don't arbitrary change the image orientation. By using the library you can set the argument angle_pm_90 to True to have an angle between -90 and 90 degrees.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Determine the skew of an image
- Determine the skew deviation of an image
deskew Key Features
deskew Examples and Code Snippets
created_files = set()
for event in i.event_gen(yield_nones=False):
(_, type_names, path, filename) = event
if "IN_CREATE" in type_names:
created_files.add(filename)
if "IN_CLOSE_WRITE" in type_n
total_pages = len(pdf.pages)
for file in os.listdir(directory):
filename = os.fsdecode(file)
if filename.endswith('.pdf'):
with pdfplumber.open(file) as pdf:
page = pdf.pages[0]
convert fabric.jpg -deskew 50% result.jpg
cv2.getAffineTransform(corners, dest_corners) # requires 3 points
cv2.getPerspectiveTransform(corners, dest_corners) # requires 4 points
cv2.warpAffine(...)
cv2.warpPerspective(...)
# Load the image
img_predict = cv2.imread('predict.png', 0)
# Preprocessing: this image is inverted compared to the training data
# Here it is inverted back
img_predict = np.invert(img_predict)
# Preprocessing: it also has a completely d
import re
text = '''Deskew 1.20 (2016-09-01) by Marek Mauder x64\r\n
http://galfar.vevb.net/deskew/\r\nLoad input file - time taken: 192,956
us\r\n
Preparing input image (1514538.png) ...\r\nCalculating skew
angle...\r\nSkew detection
""" Import required modules"""
from .deskew import *
from .skew_detect import *
plt.imshow(cv2.cvtColor(im_out, cv2.COLOR_BGR2RGB))
textdeskew input.jpg deskew.png
textcleaner -f 25 -o 10 -g -e normalize -s 1 deskew.png deskew_clean.png
convert input.jpg -deskew 40% input_deskew.png
convert inpu
img = deskew(img)
img = (img - img.min()) / (img.max() - img.min())
def deskew(image):
c,v = moments(image)
alpha = v[0,1]/v[0,0]
affine = np.array([[1,0],[alpha,1]])
ocenter = np.array(image.shape)
Community Discussions
Trending Discussions on deskew
QUESTION
After upgrading from OpenCV 3.2 to 4.5 I get a couple of compile errors. A few constants seems to have changed names
...ANSWER
Answered 2022-Apr-08 at 14:49It's a matter of versions. OpenCV started as a heap of C code. Those preprocessor #defines all started with CV_...
as a scoping hack.
OpenCV v2.0 introduced the C++ API. Constants now live in the cv
namespace.
The old #defines were kept in v2 and v3 so people could transition more easily. In OpenCV v4, all the old C API was axed. It is an ex-API *whack*
Practically, for everything that can't be found, try replacing like so:
CV_FILLED
=>cv::FILLED
CV_ADAPTIVE_THRESH_GAUSSIAN_C
=>cv::ADAPTIVE_THRESH_GAUSSIAN_C
CV_*
=>cv::*
Exception: the data type/depth codes (CV_8UC3
...) are still valid. Bulk string replacement on anything CV_
is not recommended.
QUESTION
I previously posted how to auto fix a skewed image, is there a way to simply detect that it is skewed with image magick? I.e. is there a command that I could run on two images, one skewed and one not, and use that output as the determinant of whether it's skewed?
Thanks for any help, Kevin
...ANSWER
Answered 2022-Mar-09 at 22:30Correction to my comment above. There is a way to determine the skew angle in Imagemagick if you have regular lines of text.
Input:
QUESTION
Following this approach, deskewing works great, how do I autocrop so it the outer border comes in until it finds a mostly white contiguous rectangle, so it could be auto-cropped after deskewing?
...ANSWER
Answered 2022-Mar-05 at 20:53If you are using Imagemagick 7, you can do an extreme trim using the new -define trim:percent-background=0% to remove all the background from the image. See https://imagemagick.org/script/command-line-options.php#trim
Input:
QUESTION
I am trying to use Pytesseract to read the digits from the following image:
Unfortunately, the program is not returning with any solution, even after using greyscale, thresholding, noise detection or canny edge detection. When using a config to whitelist only digits and $/, the program stops detecting even the high resolution image. (here)
The code is as follows:
...ANSWER
Answered 2022-Jan-16 at 17:09You apply multiple simple thresholding consecutively, but you should also test it with other types of thresholding such as adaptive and inRange.
For example, if you use inRange thresholding for the given example:
The result for the high resolution image will be:
The output for the 0.38 version:
QUESTION
i would like to use ocrmypdf to convert some pdf-file from a picture to a readable pdf -
Tried it with the following simple code: (the invoice.pdf is of course available in the same path as the python-script and the output.pdf should be generated)
...ANSWER
Answered 2022-Jan-15 at 19:26Sometimes the first error message may be misleading without a clear cause
In this case the primary message "The system cannot find the specified file"
Will lead a user to concentrate on why a filename is not correct, as in this case.
What the error should report is that a required file in the dependencies was not found. which can be caused by one or more Tesseract or related Leptonica / Language data files not in the correct location either due to no install or poor install.
It transpired that installing tesseract on windows from https://github.com/UB-Mannheim/tesseract/wiki "the script now works fine"
Note a missing dependency was the cause of a similar message here Import ocrmypdf in Visual Stdio Code in Python
QUESTION
In a python script I am watching a directory for new files coming from a scanner. Currently my code is only reacting on the IN_CLOSE_WRITE event. I am aware that the right way would be to watch out for a IN_CREATE event followed by a IN_CLOSE_WRITE event.
My current code looks like this:
...ANSWER
Answered 2021-Sep-28 at 16:22Add the created files to a set
, then check the set when you get the IN_CLOSE_WRITE
event.
QUESTION
I'm trying use OpenCV (4.4.0) to draw the contours of digits in image. But it doesn't work for me. Below my code:
...ANSWER
Answered 2020-Dec-03 at 08:17import cv2
im = cv2.imread('1742.jpg')
blur = cv2.GaussianBlur(im, (5, 5), 0)
edged = cv2.Canny(blur, 0, 150)
contours, _ = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
"""
draw a rectangle around those contours on main image
"""
[x,y,w,h] = cv2.boundingRect(contour)
cv2.rectangle(im, (x,y), (x+w,y+h), (0, 255, 0), 1)
cv2.imshow('Final Image with Contours', im)
cv2.waitKey()
cv2.imwrite('final.jpg',im)
QUESTION
I used Zbar (and ZXing) to read the QR code in many images like the below one, but both failed to detect it. I think I need some transformation, because when I use ZBarImg from console, it fails. On the other side, when I use ZBarCam and I put the document in front of the webcam on my laptop, it detects and decodes QR code instantly.
There are images that QR is detected correctly and images really similar to the successful ones that fail.
I tried to use ImageMagick to resize the image, remove borders, greyscale, blur it, deskew, multiple scripts from @fmw42 "Fred's ImageMagick Scripts" (unperspective...). Nothing helped. I judge it has to be some simple transformation, because ZBarCam does it almost instantly.
Do you have any idea?
...ANSWER
Answered 2020-Nov-14 at 21:36I am not sure what you have tried in Imagemagick, but my unperspective will not help this image. It will not correct for wrinkles.
But here is what I would do. First threshold, then apply morphology. The use connected components to get get the bounding box of QR code block. The crop the QR code out of the original image and use morphology to make the black regions more distinct.
Input:
QUESTION
My goal is to achieve image deskewing and I'm using OpenCV. My first step is to convert a bitmap to a Mat, after that I use the function computeSkew(matImg)
as you can see below. Unfortunately this isn't working as I get the following error message. Please help me to solve the problem.
ANSWER
Answered 2020-Oct-10 at 07:26The problem is with your Core.findNonZero
call. You are providing an incompatible input Mat
to it. The input is expected to be a single channel 8-bit image. From your code, it looks like you are providing a colour image to your deskew function and ultimately the Core.findNonZero
call. Try converting the image to grayscale first prior to thresholding:
QUESTION
I have used Projection Profile
method on my binary images to get the deskew version. Everything is fine but the rotated image is having Black areas where the deskewing has been applied. How can I convert that area to white instead of black. Below is the code for Projection Profile.
ANSWER
Answered 2020-Sep-03 at 13:05The cv2.warpaffine documentation states that the function takes an optional argument namely borderValue
. By default this value is (0, 0, 0)
, You can change this by calling your warpaffine routine as:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install deskew
You can use deskew like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page