123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using bbiwarg.Detectors.Fingers;
- 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;
- private int width;
- private int height;
- private DepthImage depthImage;
- private EdgeImage edgeImage;
- private TouchImage touchImage;
- private PalmImage palmImage;
- private FingerDetector fingerDetector;
- private TouchDetector touchDetector;
- private TouchTracker touchTracker;
- public VideoHandle(IInputProvider inputProvider) {
- this.inputProvider = inputProvider;
- //initialize trackers
- touchTracker = new TouchTracker();
- }
- public void start() {
- inputProvider.init();
- inputProvider.start();
- inputProvider.updateFrame();
- processFrameUpdate();
- }
-
- public void stop() {
- inputProvider.stop();
- }
- public void nextFrame()
- {
- if (inputProvider.isActive())
- {
- inputProvider.releaseFrame();
- inputProvider.updateFrame();
- processFrameUpdate();
- }
- else
- {
- inputProvider.stop();
- }
- }
- public int getWidth()
- {
- return width;
- }
- public int getHeight()
- {
- return height;
- }
- public Int16 getDepthAt(int x, int y) {
- return depthImage.getDepthAt(x, y);
- }
- public float getRelativeDepth(int x, int y) {
- return depthImage.getRelativeDepth(x, y);
- }
- public bool isEdgeAt(int x, int y) {
- return edgeImage.isEdgeAt(x, y);
- }
- public bool isPossibleFingerPointAt(int x, int y) {
- return fingerDetector.isPossibleFingerPointAt(x, y);
- }
- public bool isFingerPointAt(int x, int y) {
- return fingerDetector.isFingerPointAt(x, y);
- }
- public bool isPalmPointAt(int x, int y) {
- return palmImage.belongsToPalm(x, y);
- }
- public TouchImageState getTouchImageStateAt(int x, int y) {
- return touchImage.getStateAt(x, y);
- }
- private void processFrameUpdate()
- {
- //read data from inputProvider
- inputFrame = inputProvider.getInputFrame();
- width = inputFrame.getWidth();
- height = inputFrame.getHeight();
- //create depthImage
- Image<Gray, Int16> image = new Image<Gray, Int16>(width, height);
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- image.Data[y, x, 0] = inputFrame.getDepthAt(x, y);
- }
- }
- depthImage = new DepthImage(width, height, image);
- //create edgeImage
- edgeImage = new EdgeImage(depthImage);
- //detect fingers
- fingerDetector = new FingerDetector(depthImage, edgeImage);
- //create touchImage
- touchImage = new TouchImage(depthImage);
- //detect touchEvents
- touchDetector = new TouchDetector(fingerDetector.getFingers(), depthImage, touchImage);
- //track touchEvents
- touchTracker.setDetectedTouchEventsThisFrame(touchDetector.getTouchEvents(), touchImage);
- palmImage = new PalmImage(edgeImage);
- }
- }
- }
-
|