Android Open Source - scanNedit Skew






From Project

Back to project page scanNedit.

License

The source code is released under:

MIT License

If you think the Android project scanNedit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2011 Google Inc.//from  www .  j a v  a2  s. c  om
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.googlecode.leptonica.android;

/**
 * Image rotation and skew detection methods.
 *
 * @author alanv@google.com (Alan Viverette)
 */
public class Skew {
    static {
        System.loadLibrary("lept");
    }

    // Text alignment defaults
    
    /** Default range for sweep, will detect rotation of + or - 30 degrees. */
    public final static float SWEEP_RANGE = 30.0f;

    /** Default sweep delta, reasonably accurate within 0.05 degrees. */
    public final static float SWEEP_DELTA = 5.0f;

    /** Default sweep reduction, one-eighth the size of the original image. */
    public final static int SWEEP_REDUCTION = 8;

    /** Default sweep reduction, one-fourth the size of the original image. */
    public final static int SEARCH_REDUCTION = 4;

    /** Default search minimum delta, reasonably accurate within 0.05 degrees. */
    public final static float SEARCH_MIN_DELTA = 0.01f;

    /** 
     * Finds and returns the skew angle using default parameters.
     * 
     * @param pixs Input pix (1 bpp).
     * @return the detected skew angle, or 0.0 on failure
     */
    public static float findSkew(Pix pixs) {
        return findSkew(pixs, SWEEP_RANGE, SWEEP_DELTA, SWEEP_REDUCTION, SEARCH_REDUCTION,
                SEARCH_MIN_DELTA);
    }

    /**
     * Finds and returns the skew angle, doing first a sweep through a set of
     * equal angles, and then doing a binary search until convergence.
     * <p>
     * Notes:
     * <ol>
     * <li>In computing the differential line sum variance score, we sum the
     * result over scanlines, but we always skip:
     * <ul>
     * <li>at least one scanline
     * <li>not more than 10% of the image height
     * <li>not more than 5% of the image width
     * </ul>
     * </ol>
     *
     * @param pixs Input pix (1 bpp).
     * @param sweepRange Half the full search range, assumed about 0; in
     *            degrees.
     * @param sweepDelta Angle increment of sweep; in degrees.
     * @param sweepReduction Sweep reduction factor = 1, 2, 4 or 8.
     * @param searchReduction Binary search reduction factor = 1, 2, 4 or 8; and
     *            must not exceed redsweep.
     * @param searchMinDelta Minimum binary search increment angle; in degrees.
     * @return the detected skew angle, or 0.0 on failure
     */
    public static float findSkew(Pix pixs, float sweepRange, float sweepDelta, int sweepReduction,
            int searchReduction, float searchMinDelta) {
        if (pixs == null)
            throw new IllegalArgumentException("Source pix must be non-null");

        return nativeFindSkew(pixs.mNativePix, sweepRange, sweepDelta, sweepReduction,
                searchReduction, searchMinDelta);
    }

    // ***************
    // * NATIVE CODE *
    // ***************

    private static native float nativeFindSkew(int nativePix, float sweepRange, float sweepDelta,
            int sweepReduction, int searchReduction, float searchMinDelta);

}




Java Source Code List

com.googlecode.leptonica.android.AdaptiveMap.java
com.googlecode.leptonica.android.Binarize.java
com.googlecode.leptonica.android.Box.java
com.googlecode.leptonica.android.Constants.java
com.googlecode.leptonica.android.Convert.java
com.googlecode.leptonica.android.Enhance.java
com.googlecode.leptonica.android.JpegIO.java
com.googlecode.leptonica.android.Pix.java
com.googlecode.leptonica.android.Pixa.java
com.googlecode.leptonica.android.ReadFile.java
com.googlecode.leptonica.android.Rotate.java
com.googlecode.leptonica.android.Scale.java
com.googlecode.leptonica.android.Skew.java
com.googlecode.leptonica.android.WriteFile.java
com.googlecode.tesseract.android.TessBaseAPI.java
com.markupartist.android.widget.ActionBar.java
com.markupartist.android.widget.ActionBar_three.java
com.markupartist.android.widget.ActionBar_two.java
com.markupartist.android.widget.ScrollingTextView.java
com.me.android.scanNedit.CameraActivity.java
com.me.android.scanNedit.CropOptionAdapter.java
com.me.android.scanNedit.CropOption.java
com.me.android.scanNedit.FileCache.java
com.me.android.scanNedit.GalleryActivity.java
com.me.android.scanNedit.HelpActivity.java
com.me.android.scanNedit.ImageLoader.java
com.me.android.scanNedit.LazyAdapter.java
com.me.android.scanNedit.MemoryCache.java
com.me.android.scanNedit.Picture.java
com.me.android.scanNedit.SampleActivity.java
com.me.android.scanNedit.StartActivity.java
com.me.android.scanNedit.TessBaseAPITest.java
com.me.android.scanNedit.Utils.java
com.me.android.scanNedit.XMLParser.java