deskew | Library used to deskew a scanned document | Computer Vision library

 by   sbrunner Python Version: 1.5.1 License: MIT

kandi X-RAY | deskew Summary

kandi X-RAY | deskew Summary

deskew is a Python library typically used in Artificial Intelligence, Computer Vision, OpenCV applications. deskew has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. However deskew build file is not available. You can install using 'pip install deskew' or download it from GitHub, PyPI.

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

            kandi-support Support

              deskew has a low active ecosystem.
              It has 306 star(s) with 38 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 6 open issues and 14 have been closed. On average issues are closed in 180 days. There are 3 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of deskew is 1.5.1

            kandi-Quality Quality

              deskew has 0 bugs and 1 code smells.

            kandi-Security Security

              deskew has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              deskew code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              deskew is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              deskew releases are available to install and integrate.
              Deployable package is available in PyPI.
              deskew has no build file. You will be need to create the build yourself to build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              deskew saves you 69 person hours of effort in developing the same functionality from scratch.
              It has 226 lines of code, 8 functions and 4 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed deskew and discovered the below as its top functions. This is intended to give you an instant insight into deskew implemented functionality, and help decide if they suit your requirements.
            • Determine the skew of an image
            • Determine the skew deviation of an image
            Get all kandi verified functions for this library.

            deskew Key Features

            No Key Features are available at this moment for deskew.

            deskew Examples and Code Snippets

            Python inotify - Execute function upon new file creation
            Pythondot img1Lines of Code : 18dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                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
            How do I extract all of the text from a PDF using indexing
            Pythondot img2Lines of Code : 25dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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]
                    
            Counting white clusters horizontally in a processed fabric
            Pythondot img3Lines of Code : 2dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
             convert fabric.jpg -deskew 50% result.jpg
            
            Detect text and deskew
            Pythondot img4Lines of Code : 6dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            cv2.getAffineTransform(corners, dest_corners)    # requires 3 points
            cv2.getPerspectiveTransform(corners, dest_corners)    # requires 4 points
            
             cv2.warpAffine(...)
             cv2.warpPerspective(...)
            
            How to implement .dat file for handwritten recognition using SVM in Python
            Pythondot img5Lines of Code : 23dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # 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
            Regex: Search using (anchor string + expression). but extract only the expression
            Pythondot img6Lines of Code : 15dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            ImportError in Jupyter Notebook
            Pythondot img7Lines of Code : 4dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            """ Import required modules"""
            from .deskew import *
            from .skew_detect import * 
            
            Python - Displaying the image with the original colors
            Pythondot img8Lines of Code : 2dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            plt.imshow(cv2.cvtColor(im_out, cv2.COLOR_BGR2RGB))
            
            Receipt reading using TesserOCR
            Pythondot img9Lines of Code : 10dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            Deskew MNIST images
            Pythondot img10Lines of Code : 12dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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

            QUESTION

            Upgrade OpenCV 4.5 - constants not declared
            Asked 2022-Apr-08 at 14:49

            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:49

            It'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.

            Source https://stackoverflow.com/questions/71797193

            QUESTION

            Detect skewed image with imagemagick
            Asked 2022-Mar-09 at 22:30

            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:30

            Correction to my comment above. There is a way to determine the skew angle in Imagemagick if you have regular lines of text.

            Input:

            Source https://stackoverflow.com/questions/71413564

            QUESTION

            how to autocrop a deskewed scanned image
            Asked 2022-Mar-05 at 20:53

            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:53

            If 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:

            Source https://stackoverflow.com/questions/71365280

            QUESTION

            Pytesseract Not Recognising Text
            Asked 2022-Jan-16 at 17:09

            I am trying to use Pytesseract to read the digits from the following image:

            Low Resolution 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:09

            You 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:

            Source https://stackoverflow.com/questions/70560581

            QUESTION

            ocrmypdf - could not find source-pdf?
            Asked 2022-Jan-15 at 19:26

            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:26

            Sometimes 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

            Source https://stackoverflow.com/questions/70717279

            QUESTION

            Python inotify - Execute function upon new file creation
            Asked 2021-Sep-28 at 16:22

            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:22

            Add the created files to a set, then check the set when you get the IN_CLOSE_WRITE event.

            Source https://stackoverflow.com/questions/69363827

            QUESTION

            cv2.drawContours function does not draw the contours properly
            Asked 2020-Dec-03 at 18:34

            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:17
            import 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)
            

            Source https://stackoverflow.com/questions/65120547

            QUESTION

            QR code detection with ZBar from console fails for valid QR codes (ZBarCam from camera detects them fine)
            Asked 2020-Nov-14 at 21:36

            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:36

            I 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:

            Source https://stackoverflow.com/questions/64831824

            QUESTION

            src.type() == CV_8UC1 assertion failed when deskewing image
            Asked 2020-Oct-13 at 23:14

            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:26

            The 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:

            Source https://stackoverflow.com/questions/64283771

            QUESTION

            Change the background of rotated image to White instead of black after using Projection Profile Deskew method in OpenCV (or skimage)
            Asked 2020-Sep-03 at 13:05

            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:05

            The 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:

            Source https://stackoverflow.com/questions/63722635

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install deskew

            You can install using 'pip install deskew' or download it from GitHub, PyPI.
            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

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install deskew

          • CLONE
          • HTTPS

            https://github.com/sbrunner/deskew.git

          • CLI

            gh repo clone sbrunner/deskew

          • sshUrl

            git@github.com:sbrunner/deskew.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link