123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using bbiwarg.Utility;
- using bbiwarg.Detectors.Fingers;
- using bbiwarg.Detectors.Palm;
- using bbiwarg.Detectors.Touch;
- using bbiwarg.Images;
- using bbiwarg.InputProviders;
- using Emgu.CV;
- using Emgu.CV.Structure;
- namespace bbiwarg
- {
- class VideoHandle
- {
- private IInputProvider inputProvider;
- private InputFrame inputFrame;
- public int Width { get; private set; }
- public int Height { get; private set; }
- private DepthImage depthImage;
- private EdgeImage edgeImage;
- private PalmImage palmImage;
- private TouchImage touchImage;
- private FingerImage fingerImage;
- private FingerDetector fingerDetector;
- private PalmDetector palmDetector;
- private TouchDetector touchDetector;
- private PalmTouchDetector palmTouchDetector;
- private FingerTracker fingerTracker;
- private TouchTracker touchTracker;
- public VideoHandle(IInputProvider inputProvider)
- {
- this.inputProvider = inputProvider;
- //initialize trackers
- touchTracker = new TouchTracker();
- fingerTracker = new FingerTracker();
- }
- public void start()
- {
- inputProvider.init();
- inputProvider.start();
- inputProvider.updateFrame();
- processFrameUpdate();
- }
- public void stop()
- {
- inputProvider.stop();
- }
- public int getCurrentMovieFrame()
- {
- return inputProvider.getCurrentMovieFrame();
- }
- public bool sourceIsMovie()
- {
- return inputProvider.sourceIsMovie();
- }
- public void reversePlay()
- {
- inputProvider.reversePlay();
- }
- public void pauseMovie()
- {
- inputProvider.pauseMovie();
- }
- public void unpauseMovie()
- {
- inputProvider.unpauseMovie();
- }
- public void nextFrame()
- {
- if (inputProvider.isActive())
- {
- inputProvider.releaseFrame();
- inputProvider.updateFrame();
- processFrameUpdate();
- }
- else
- {
- inputProvider.stop();
- }
- }
- public Int16 getDepthAt(int x, int y)
- {
- return depthImage.getDepthAt(x, y);
- }
- public float getRelativeDepth(int x, int y)
- {
- return depthImage.getRelativeDepthAt(x, y);
- }
- public bool isEdgeAt(int x, int y)
- {
- return edgeImage.isEdgeAt(x, y);
- }
- public FingerImageState getFingerImageStateAt(int x, int y)
- {
- return fingerImage.getStateAt(x, y);
- }
- public PalmImageState getPalmImageStateAt(int x, int y)
- {
- return palmImage.getStateAt(x, y);
- }
- public TouchImageState getTouchImageStateAt(int x, int y)
- {
- return touchImage.getStateAt(x, y);
- }
- public List<PalmTouchEvent> getPalmTouchEvents()
- {
- return palmTouchDetector.PalmTouchEvents;
- }
- private void processFrameUpdate()
- {
- Timer.start("processFrameUpdate");
- //read data from inputProvider
- Timer.start("readInputData");
- inputFrame = inputProvider.getInputFrame();
- Width = inputFrame.Width;
- Height = inputFrame.Height;
- Timer.stop("readInputData");
- //create depthImage
- Timer.start("createDepthImage");
- Image<Gray, Int16> image = new Image<Gray, Int16>(Width, Height, Width * 2, inputFrame.RawDepthData);
- depthImage = new DepthImage(image);
- Timer.stop("createDepthImage");
- //create images
- Timer.start("createOtherImages");
- edgeImage = new EdgeImage(depthImage);
- touchImage = new TouchImage(Width, Height);
- fingerImage = new FingerImage(Width, Height);
- palmImage = new PalmImage(Width, Height);
- Timer.stop("createOtherImages");
- //detect fingers
- Timer.start("fingerDetection");
- fingerDetector = new FingerDetector(depthImage, edgeImage, fingerImage);
- Timer.stop("fingerDetection");
- //track fingers
- Timer.start("fingerTracking");
- fingerTracker.setDetectedTouchEventsThisFrame(fingerDetector.Fingers, fingerImage);
- Timer.stop("fingerTracking");
- //detect palm
- Timer.start("palmDetection");
- palmDetector = new PalmDetector(depthImage, edgeImage, fingerDetector.Fingers, palmImage);
- Timer.stop("palmDetection");
- //detect touchEvents
- Timer.start("touchDetection");
- touchDetector = new TouchDetector(fingerTracker.TrackedFingers, depthImage, touchImage);
- if (palmDetector.PalmQuad != null)
- palmTouchDetector = new PalmTouchDetector(touchDetector.TouchEvents, palmDetector.PalmQuad);
- Timer.stop("touchDetection");
- //track touchEvents
- Timer.start("touchTracking");
- touchTracker.setDetectedTouchEventsThisFrame(touchDetector.TouchEvents, touchImage);
- Timer.stop("touchTracking");
- Timer.stop("processFrameUpdate");
- }
- }
- }
|