Git Product home page Git Product logo

perspec's Introduction

Icon Perspec

App and workflow to perspectively correct images. For example whiteboards, document scans, or facades.

App Workflow

Step Description Result
1 Take photos Original image
2 Open Perspec app Opened Perspec App
3 Drop the images onto the window Dropped image
4 Mark the corners by clicking on them Marked corners
5 Click one of the save buttons (or [Enter]) Corrected image

Installation

WARNING: Perspec currently only works on macOS and Linux. Any help to make it work on Microsoft (Ticket) would be greatly appreciated!

Prebuilt

You can get this (and previous) versions from the releases page.

The current nightly version can be downloaded from https://github.com/feramhq/Perspec/actions. However, it's necessary to fix the file permissions after download:

chmod +x \
  ./Perspec.app/Contents/MacOS/Perspec \
  ./Perspec.app/Contents/Resources/{perspec,script,imagemagick/bin/convert}

On macOS you can also install it via this Homebrew tap:

brew install --cask ad-si/tap/perspec

From Source

Build it from source with Haskell's stack.

Platypus, with command line tools enabled , is required to build from source.

git clone https://github.com/feramhq/Perspec
cd Perspec
make install

This copies the Perspec.app to your /Applications directory and makes the perspec command available on your path. You can then either drop images on the app window, or use it via the CLI like perspec fix image.jpeg

Usage via CLI

It's also possible to directly invoke Perspec via the CLI like so:

/Applications/Perspec.app/Contents/Resources/perspec fix path/to/image.jpeg

You can also pass several images and they will all be opened one after another. This is very useful for batch correcting a large set of images.

Photo Digitization Workflow

  1. Take photos
    1. Use camera app which lets you lock rotation (e.g. OpenCamera). Otherwise check out the guide below to fix rotation.
    2. Use a sound activated camera to take photos simply by clicking your tongue or snipping your finger. E.g. with:
  2. Use perspec rename sub-command to fix order and names of scanned files.
  3. Verify that
    • All pages were captured and have the correct filename
    • Images are sharp enough
    • Images have a high contrast
    • Images have correct orientation
  4. For best image quality convert images optionally to a lossless format (e.g. png), apply rotations, and convert them to grayscale. Attention: Exclude the covers!
    mogrify -verbose -format png \
      -auto-orient -colorspace gray photos/*.jpeg
  5. Use Perspec to crop images
    perspec fix photos/*.png

Additional Steps

Improve colors with one of the following steps:

  1. Normalize dynamic range:
mogrify -verbose -normalize photos/*.png
  1. Convert to black and white:
    #! /usr/bin/env bash
    
    find . -iname "*.png" | \
    while read -r file
    do
      convert \
        -verbose \
        "$file" \
        \( +clone -blur 0x60 -brightness-contrast 40 \) \
        -compose minus \
        -composite \
        -negate \
        -auto-threshold otsu \
        "$(basename "$file" ".png")"-fixed.png
    done

In order to rotate all photos to portrait mode you can use either

mogrify -verbose -auto-orient -rotate "90>" photos/*.jpeg

or

mogrify -verbose -auto-orient -rotate "-90>" photos/*.jpeg

Features

  • Rescale image on viewport change
  • Handle JPEG rotation
  • Draw lines between corners to simplify guessing of clipped corners
  • Bundle Imagemagick
  • Better error if wrong file format is dropped (images/error-message.jpg)
  • Center Perspec window on screen
  • Drag'n'Drop for corner markers
  • "Submit" button
  • "Convert to Grayscale" button
  • Add support for custom output size (e.g. A4)
  • Manual rotation buttons
  • Zoom view for corners
  • Label corner markers

Algorithms

Perspective Transformation

Once the corners are marked, the correction is equivalent to:

convert \
  images/example.jpg \
  -distort Perspective \
    '8,35 0,0 27,73 0,66 90,72 63,66 67,10 63,0' \
  -crop 63x66+0+0 \
  images/example-fixed.jpg

Grayscale Conversion

Converts image to grayscale and normalizes the range of values afterwards. (Uses Imagemagick's -colorspace gray -normalize)

BW Conversion

Converts image to binary format with OTSU's method. (Uses Imagemagick's -auto-threshold OTSU -monochrome)

Interpolation of Missing Parts

Perspec automatically interpolates missing parts by using the closest pixel. (https://www.imagemagick.org/Usage/misc/#edge)

Technologies

Related

Check out ad-si/awesome-scanning for an extensive list of related projects.

perspec's People

Contributors

ad-si avatar jaccokrijnen avatar lancelet avatar raybb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

perspec's Issues

ImageMagick Failure on MacOS

Hello, thanks for your work! This application is simple and should do the trick for me.

I installed it and followed the procedure. I get the following error in the window:

​dyld: lazy symbol binding failed: Symbol not found: _aligned_alloc
  Referenced from: /Applications/Perspec.app/Contents/Resources/imagemagick/lib/libMagickCore-7.Q16HDRI.7.dylib (which was built for Mac OS X 10.15)
  Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _aligned_alloc
  Referenced from: /Applications/Perspec.app/Contents/Resources/imagemagick/lib/libMagickCore-7.Q16HDRI.7.dylib (which was built for Mac OS X 10.15)
  Expected in: /usr/lib/libSystem.B.dylib
Loaded file /my/dir/image.jpg (1536,1152)
Starting the app …
Target shape: (1283.667,802.22144)
Marked corners: ((157.2,76.8),(1444.8,68.4),(1436.4,892.80005),(157.2,856.80005))
Arguments for convert command:
/my/dir/image.jpg
-define
distort:viewport=1283.667x802.22144+0+0
-virtual-pixel
black
-distort
Perspective
157.2,76.8 0.0,0.0 157.2,856.80005 0.0,802.22144 1436.4,892.80005 1283.667,802.22144 1444.8,68.4 1283.667,0.0
+repage
/my/dir/image-fixed.jpg
perspec: callProcess: ./imagemagick/bin/convert "/my/dir/image.jpg" "-define" "distort:viewport=1283.667x802.22144+0+0" "-virtual-pixel" "black" "-distort" "Perspective" "157.2,76.8 0.0,0.0 157.2,856.80005 0.0,802.22144 1436.4,892.80005 1283.667,802.22144 1444.8,68.4 1283.667,0.0" "+repage" "/my/dir/image-fixed.jpg" (exit -6): failed

Perhaps you would see instantly what I need to do to fix this?

Image not found error on macOS 10.15.7

I installed using the brew command.

According to #5 it may be because I'm on a newer version of macOS.

When I crop an image I get the following error:

​2021-04-03 10:11:39.750 perspec[10167:89305] -[NSIBObjectData initWithCoder:]: corrupt and unarchivable nib file
("/Users/210118/Downloads/1.jpeg","/Users/210118/Downloads/1-fixed.jpeg",(((194.99998,176.66666),(0.0,0.0)),((126.666664,1308.3333),(0.0,1137.001)),((1021.6666,1335.0),(848.63666,1137.001)),((996.6666,194.99998),(848.63666,0.0))),(848.63666,1137.001))
dyld: Library not loaded: /opt/X11/lib/libXt.6.dylib
  Referenced from: /Applications/Perspec.app/Contents/Resources/./imagemagick/bin/convert
  Reason: image not found
Loaded file /Users/210118/Downloads/1.jpeg (1200,1600)
with orientation Normal
Starting the app …
Target shape: (848.63666,1137.001)
Marked corners: ((194.99998,176.66666),(996.6666,194.99998),(1021.6666,1335.0),(126.666664,1308.3333))
Arguments for convert command:
/Users/210118/Downloads/1.jpeg
-auto-orient
-define
distort:viewport=848.63666x1137.001+0+0
-virtual-pixel
black
-distort
Perspective
194.99998,176.66666 0.0,0.0 126.666664,1308.3333 0.0,1137.001 1021.6666,1335.0 848.63666,1137.001 996.6666,194.99998 848.63666,0.0
+repage
/Users/210118/Downloads/1-fixed.jpeg
callProcess: ./imagemagick/bin/convert "/Users/210118/Downloads/1.jpeg" "-auto-orient" "-define" "distort:viewport=848.63666x1137.001+0+0" "-virtual-pixel" "black" "-distort" "Perspective" "194.99998,176.66666 0.0,0.0 126.666664,1308.3333 0.0,1137.001 1021.6666,1335.0 848.63666,1137.001 996.6666,194.99998 848.63666,0.0" "+repage" "/Users/210118/Downloads/1-fixed.jpeg" (exit -6): failed

PS: Thanks for all the hard work in making this app. It is very handy :)

Fix memory leak

There seems to be a memory leak, as it needs increasing amounts of memory when simply left open.

Embed Imagemagick binary

Possible solutions:

Buying license is not possible

Hello, how can i buy via PayPal? I tried to buy a license via the webpage (https://feram.gumroad.com/l/perspec) but it doesn't work because the fields are flickering after i entered some data. Further i have security concerns about to give my credit card data on this the site because it is not verified anywhere.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.