Package astro.detect.bgs

Source Code of astro.detect.bgs.MOGBGS

/*
* Copyright (C) 2014 Tamás Szeleczki <sztforums@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package astro.detect.bgs;

import javax.swing.JFrame;
import org.opencv.core.Mat;
import org.opencv.video.BackgroundSubtractor;

/**
* @author Tamás Szeleczki <sztforums@gmail.com>
* @see <a href="http://szelinet.hu/thesis/">BSc Thesis in Engineering Information Technology</a>
*/
public class MOGBGS extends BGS {
    private final BackgroundSubtractor bgs;
    private float movePercent;

    private Mat fg;
   
    public MOGBGS( BackgroundSubtractor bgs ) {
        this.fg = null;
        this.bgs = bgs;
    }

    @Override
    public void process(Mat frame) {
        if( this.fg == null )
            this.fg = new Mat(frame.width(), frame.height(), frame.type());
        this.bgs.apply(frame, this.fg);
        if( this.isShowFg() && this.showWindow.getState() != JFrame.ICONIFIED )
            this.showWindow.show(this.fg);
    }

    @Override
    public boolean isMoving() {
        boolean move = false;
        int white = 0;
       

        for( int j = 0; j < this.fg.height(); j++ ) {
            for( int i = 0; i < this.fg.width(); i++ ) {
                white += (this.fg.get(j, i)[0] == 0) ? 0 : 1;
            }
        }
       
        if( white >= this.fg.total() * this.movePercent )
            return true;
       
        return move;
    }
   
    public float getMovePercent() {
        return movePercent;
    }

    public void setMovePercent(float movePercent) {
        this.movePercent = movePercent;
    }
   
}
TOP

Related Classes of astro.detect.bgs.MOGBGS

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.