Package astro.server.stream

Source Code of astro.server.stream.SnapshotStream

package astro.server.stream;

import astro.detect.bgs.BGS;
import astro.detect.bgs.MOGBGS;
import astro.util.ImgConverter;
import astro.util.Logging;
import java.awt.Canvas;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.opencv.video.BackgroundSubtractorMOG2;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;

//
//  Generated by StarUML(tm) Java Add-In
//
//  @ Project : Untitled
//  @ File Name : SnapshotStream.java
//
//




public class SnapshotStream implements Stream{

    public SnapshotStream(Canvas canvas){
  //NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\VLC\\");
  //Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

  running = false;

  networkCache = 300;

  streamPort = 8080;
  factory = new MediaPlayerFactory("--no-video-title-show");

  videoSurface = factory.newVideoSurface(canvas);
    }
   
    public void setDirectory(String dir) {
  directory = dir;
    }

    @Override
    public void start() {
  stream = factory.newEmbeddedMediaPlayer();
  stream.setVideoSurface(videoSurface);
  String[] options = {" :network-caching=500 :clock-jitter=0"};
  stream.prepareMedia("http://localhost:8080/stream.asf", options);
  if(stream.start()){
      Logging.getInstance().toFile("Snapshot Stream Started");
  }else
      Logging.getInstance().toFile("Snapshot Stream Failed to Start!");
    }

    @Override
    public void stop() {
  if(stream.isPlaying())
      stream.stop()
    }

    @Override
    public void initialize() {
 
    }
   
    public String takePicture(String path)
    {
        String strEpoch = null;
  String fullFileName = path;
  if(stream.isPlaying())
  {
      long epoch = System.currentTimeMillis()/1000;
     
      fullFileName += epoch +".png";
      File file = new File(fullFileName);
            //stream.saveSnapshot(file);
      BufferedImage sns;
           
            if( (sns = stream.getSnapshot()) != null ) {
                if( this.bgs == null )
                    this.bgs = new MOGBGS(new BackgroundSubtractorMOG2(10, 90f));
                this.bgs.setShowFg(true);
                ((MOGBGS)this.bgs).setMovePercent(0.01f);
                this.bgs.process(ImgConverter.toMat(sns));

                if( this.bgs.isMoving() ) {
                    try {
                        ImageIO.write(sns, "png", file);
                    } catch (FileNotFoundException ex) {
                        //TODO: Use custom logger
                        Logger.getLogger(SnapshotStream.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        //TODO: Use custom logger
                        Logger.getLogger(SnapshotStream.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    strEpoch = String.valueOf(epoch);
                    //TODO: Use custom logger
                    System.out.println(file);
                }
                return strEpoch;
            }
  }
  return null;
    }
   
    /*
        @Override
    public void run()
    {
  //running = true;
  startStream();
    }*/

    private BGS bgs = null;
    public Boolean debugMode;
    public String directory;
    private MediaPlayerFactory factory;
    private EmbeddedMediaPlayer stream;
    private CanvasVideoSurface videoSurface;
    private int networkCache;
    private int streamPort;
    public Boolean running;
}
TOP

Related Classes of astro.server.stream.SnapshotStream

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.