⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.java

📁 JavaANPR是一个自动车牌识别程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
------------------------------------------------------------------------
JavaANPR - Automatic Number Plate Recognition System for Java
------------------------------------------------------------------------

This file is a part of the JavaANPR, licensed under the terms of the
Educational Community License

Copyright (c) 2006-2007 Ondrej Martinsky. All rights reserved

This Original Work, including software, source code, documents, or
other related items, is being provided by the copyright holder(s)
subject to the terms of the Educational Community License. By
obtaining, using and/or copying this Original Work, you agree that you
have read, understand, and will comply with the following terms and
conditions of the Educational Community License:

Permission to use, copy, modify, merge, publish, distribute, and
sublicense this Original Work and its documentation, with or without
modification, for any purpose, and without fee or royalty to the
copyright holder(s) is hereby granted, provided that you include the
following on ALL copies of the Original Work or portions thereof,
including modifications or derivatives, that you make:

# The full text of the Educational Community License in a location
viewable to users of the redistributed or derivative work.

# Any pre-existing intellectual property disclaimers, notices, or terms
and conditions.

# Notice of any changes or modifications to the Original Work,
including the date the changes were made.

# Any modifications of the Original Work must be distributed in such a
manner as to avoid any confusion with the Original Work of the
copyright holders.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The name and trademarks of copyright holder(s) may NOT be used in
advertising or publicity pertaining to the Original or Derivative Works
without specific, written prior permission. Title to copyright in the
Original Work and any associated documentation will at all times remain
with the copyright holders. 

If you want to alter upon this work, you MUST attribute it in 
a) all source files
b) on every place, where is the copyright of derivated work
exactly by the following label :

---- label begin ----
This work is a derivate of the JavaANPR. JavaANPR is a intellectual 
property of Ondrej Martinsky. Please visit http://javaanpr.sourceforge.net 
for more info about JavaANPR. 
----  label end  ----

------------------------------------------------------------------------
                                         http://javaanpr.sourceforge.net
------------------------------------------------------------------------
*/



package javaanpr.imageanalysis;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
//import java.util.Collections;
//import java.util.Comparator;
import java.util.Vector;

public class Graph {
    public class Peak {
        public int left, center, right;
        public Peak(int left, int center, int right) {
            this.left = left;
            this.center = center;
            this.right = right;
        }
        public Peak(int left, int right) {
            this.left = left;
            this.center = (left+right)/2;
            this.right = right;
        }        
        public int getLeft() {
            return this.left;
        }
        public int getRight() {
            return this.right;
        }
        public int getCenter() {
            return this.center;
        }
        public int getDiff() {
            return this.right - this.left;
        }
        public void setLeft(int left) {
            this.left = left;
        }
        public void setCenter(int center) {
            this.center = center;
        }
        public void setRight(int right) {
            this.right = right;
        }
    }
    static public class ProbabilityDistributor {
        float center;
        float power;
        int leftMargin;
        int rightMargin;
        public ProbabilityDistributor(float center, float power, int leftMargin, int rightMargin) {
            this.center = center;
            this.power = power;
            this.leftMargin = Math.max(1,leftMargin);
            this.rightMargin = Math.max(1,rightMargin);
        }
        
        private float distributionFunction(float value, float positionPercentage) {
            return value * (1 - this.power * Math.abs(positionPercentage - this.center) );
        }
        
        public Vector<Float> distribute(Vector<Float> peaks) {
            Vector<Float> distributedPeaks = new Vector<Float>();
            for (int i=0; i<peaks.size(); i++) {
                if (i < leftMargin || i > peaks.size() - rightMargin) {
                    distributedPeaks.add(0f);
                } else {
                    distributedPeaks.add(distributionFunction(peaks.elementAt(i),
                            ((float)i/peaks.size())
                            )
                            );
                }
            }
            
            return distributedPeaks;
        }
    }
    
    public Vector<Peak> peaks = null;
    public Vector<Float> yValues = new Vector<Float>();
    // statistical informations
    private boolean actualAverageValue = false; // su hodnoty aktualne ?
    private boolean actualMaximumValue = false; // su hodnoty aktualne ?
    private boolean actualMinimumValue = false; // su hodnoty aktualne ?
    private float averageValue;
    private float maximumValue;
    private float minimumValue;
    
    void deActualizeFlags() {
        this.actualAverageValue = false;
        this.actualMaximumValue = false;
        this.actualMinimumValue = false;
    }
    
    // generic
    // methods for searching bands in image !
    boolean allowedInterval(Vector<Peak> peaks, int xPosition) {
        for (Peak peak : peaks)
            if (peak.left <= xPosition && xPosition <= peak.right) return false;
        return true;
    }
    public void addPeak(float value) {
        yValues.add(value);
        this.deActualizeFlags();
    }
    public void applyProbabilityDistributor(Graph.ProbabilityDistributor probability) {
        this.yValues = probability.distribute(this.yValues);
        this.deActualizeFlags();
    }
    public void negate() {
        float max = this.getMaxValue();
        for (int i=0; i<this.yValues.size(); i++)
            this.yValues.setElementAt(max - this.yValues.elementAt(i),i);

        this.deActualizeFlags();
    }
    
//    public class PeakComparer implements Comparator {
//        int sortBy; // 0 = podla sirky, 1 = podla velkosti, 2 = z lava do prava
//        Vector<Float> yValues = null;
//        
//        public PeakComparer(Vector<Float> yValues, int sortBy) {
//            this.yValues = yValues;
//            this.sortBy = sortBy;
//        }
//        
//        private float getPeakValue(Object peak) {
//            if (this.sortBy == 0) {
//                return ((Peak)peak).diff();
//            } else if (this.sortBy == 1) {
//                return this.yValues.elementAt( ((Peak)peak).center()  );
//            } else if (this.sortBy == 2) {
//                return ((Peak)peak).center();
//            }
//            return 0;
//        }
//        
//        public int compare(Object peak1, Object peak2) { // Peak
//            double comparison = this.getPeakValue(peak2) - this.getPeakValue(peak1);
//            if (comparison < 0) return -1;
//            if (comparison > 0) return 1;
//            return 0;
//        }
//    }
    
//    float getAverageValue() {
//        if (!this.actualAverageValue) {
//            float sum = 0.0f;
//            for (Float peak : this.yValues) sum += peak;
//            this.averageValue = sum/this.yValues.size();
//            this.actualAverageValue = true;
//        }
//        return this.averageValue;
//    }
//    
    
    float getAverageValue() {
        if (!this.actualAverageValue) {
            this.averageValue = getAverageValue(0,this.yValues.size());
            this.actualAverageValue = true;
        }
        return this.averageValue;
    }
    
    float getAverageValue(int a, int b) {
        float sum = 0.0f;
        for (int i=a; i<b; i++) sum+= this.yValues.elementAt(i).doubleValue();
        return sum/this.yValues.size();
    }
    

//    float getMaxValue() {
//        if (!this.actualMaximumValue) {
//            float maxValue = 0.0f;
//            for (int i=0; i<yValues.size(); i++)
//                maxValue = Math.max(maxValue, yValues.elementAt(i));
//            this.maximumValue = maxValue;
//            this.actualMaximumValue = true;
//        }
//        return this.maximumValue;
//    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -