Giter VIP home page Giter VIP logo

autocroppy's Introduction

autocroppy

Autocroppy is an improvement on traditional autocrop tools. Designed to remove black borders of scanned documents or old slides it stands out on twisted pictures or pictures which black borders are rounded or irregular.

Get Started

  1. You'll need the 32-bit version of Python 2.7. Python 3 is not yet supported, as is 64-bit.
  2. Autocroppy depends on OpenCV 2, you can get the newest version here. To get it working with Python follow this guide: http://opencvpython.blogspot.nl/2012/05/install-opencv-in-windows-for-python.html
  3. OpenCV depends on NumPy, which can be installed from http://sourceforge.net/projects/numpy/files/NumPy/

Usage

python autocroppy [input_folder] [output_folder]
	- input_folder (optional): where to grab images from, defaults to the current directory
	- output_folder (optional): where to put the processed images, defaults to 'out'

autocroppy will look for any .jpg files in the input folder, then process the image, and place it in the output folder with the same name. This behavior can be altered by tweaking the source code.

Download the files and run autocroppy without any arguments, and the 3 test images will be processed and placed in the folder out without black borders.

Tweaking

If you're looking for a great autocrop algorithm or you want to tweak autocroppy to your needs, this is what you must know.

autocroppy.py is the main file, it contains the code that selects the files and the user interface stuff. If you want to run autocroppy more carefully you can set INTERACTIVE_MODE (at the top of the file) to True. autocroppy will now show the original and processed image and ask you if you want to store the result.

autocropper.py contains the AutoCropper class which you can use for your own programs. Here is some example code.

import cv2
from autocropper import AutoCropper

img = cv2.imread("image.jpg", cv2.IMREAD_COLOR)

ac = AutoCropper(img)
ac.max_border_size = 200 	# defaults to 300
ac.safety_margin = 10 		# defaults to 4, removes extra pixels from the sides to make sure no black remains
ac.tolerance = 10 			# defaults to 4, a gray value is more likely to be considered black when you increase the tolerance

# go!
result = ac.autocrop()

autocroppy's People

Contributors

gerwin3 avatar

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.