Я уже видел на Youtube информацию о распознавании тремора Leap Motion и начал создавать это приложение с использование Leap Motion для обработки сигналов в C#. У меня возникают проблемы на первом этапе. Я не знаю, как получить и записать несколько кадров движения рук в секунду. В этом случае я хочу записать его за 10 секунд. Я не знаю библиотеку, которую я должен использовать для записи этого.
надеюсь, кто-нибудь поможет мне объяснить и поделиться тем, как кодировать его на С#... спасибо
это код, который я пробовал, но я не собирал и не запускал его, поэтому я думаю, что он не работает. Может ли кто-нибудь проверить это для меня?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Diagnostics;
using Leap;
namespace map3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, ILeapEventDelegate
{
private Controller controller = new Controller();
Leap.Frame frame;
//getting data from a frame
HandList hands;
PointableList pointables;
FingerList fingers;
ToolList tools;
private LeapEventListener listener;
private Gesture gesture = new Gesture();
private String direction;
Leap.Frame gestureFrame;
Leap.Frame fingerFrame;
private long timestamp;
private Boolean isClosing = false;
private Boolean isPlaying = false;
private Int64 lastFrameID = 0;
Thread finger_thread, gesture_thread;
public MainWindow()
{
InitializeComponent();
main_window.ResizeMode = ResizeMode.NoResize;
this.controller = new Controller();
this.listener = new LeapEventListener(this);
controller.AddListener(listener);
processFrame(frame);
//get timestamp
float framePeriod = controller.Frame(0).Timestamp - controller.Frame(1).Timestamp;
lbl_debug.Content = "Gesture";
}
private void processFrame(Leap.Frame frame)
{
if (frame.Id == lastFrameID)
return;
lastFrameID = frame.Id;
//for have an ID of an entity from a different frame
Hand hand = frame.Hand(handID);
Pointable pointable = frame.Pointable(pointableID);
Finger finger = frame.Finger(fingerID);
Tool tool = frame.Tool(toolID);
Thread.Sleep(10000);
//to save frame to file
byte[] serializedFrame = frame.Serialize;
System.IO.File.WriteAllBytes ("frame.data", serializedFrame);
}
public void Deserialize() //to read multiple frame from the saved file
{
Controller leapController = new Controller();
using (System.IO.BinaryReader br =
new System.IO.BinaryReader(System.IO.File.Open("file.data", System.IO.FileMode.Open)))
{
while (br.BaseStream.Position < br.BaseStream.Length)
{
Int32 nextBlock = br.ReadInt32();
byte[] frameData = br.ReadBytes(nextBlock);
Leap.Frame newFrame = new Leap.Frame();
newFrame.Deserialize(frameData);
}
}
}
private void btn_start_click(object sender, RoutedEventArgs e)
{
startDetect();
}
private void startDetect()
{
//maplayer.Play();
if (controller.IsConnected)
{
Leap.Frame frame = controller.Frame(); //the latest frame
Leap.Frame previous = controller.Frame(1); //the previous frame
}
isPlaying = true;
btn_start.Content = FindResource("Start"); //connecting to gui
}
delegate void LeapEventDelegate(string EventName);
public void LeapEventNotification(string EventName)
{
if (this.CheckAccess())
{
switch (EventName)
{
case "onInit":
Debug.WriteLine("Init");
break;
case "onConnect":
this.connectHandler();
break;
case "onFrame":
if (!this.isClosing)
this.processFrame(this.controller.Frame());
break;
}
}
else
{
Dispatcher.Invoke(new LeapEventDelegate(LeapEventNotification), new object[] { EventName });
}
}
void connectHandler()
{
this.controller.SetPolicy(Controller.PolicyFlag.POLICY_IMAGES);
this.controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
this.controller.Config.SetFloat("Gesture.Swipe.MinLength", 200.0f);
this.controller.Config.Save();
}
void MainWindow_Closing(object sender, EventArgs e)
{
this.isClosing = true;
this.controller.RemoveListener(this.listener);
this.controller.Dispose();
}
private void ListView_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
}
public int handID { get; set; }
public int pointableID { get; set; }
public int toolID { get; set; }
public int fingerID { get; set; }
}
public interface ILeapEventDelegate
{
void LeapEventNotification(string EventName);
}
public class FrameListener : Listener
{
public void onFrame(Controller controller)
{
Leap.Frame frame = controller.Frame();
Leap.Frame previous = controller.Frame(1);
}
}
public class LeapEventListener : Listener
{
ILeapEventDelegate eventDelegate;
public LeapEventListener(ILeapEventDelegate delegateObject)
{
this.eventDelegate = delegateObject;
}
public override void OnInit(Controller controller)
{
this.eventDelegate.LeapEventNotification("onInit");
}
public override void OnConnect(Controller controller)
{
controller.SetPolicy(Controller.PolicyFlag.POLICY_IMAGES);
controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
this.eventDelegate.LeapEventNotification("onConnect");
}
public override void OnFrame(Controller controller)
{
this.eventDelegate.LeapEventNotification("onFrame");
}
public override void OnExit(Controller controller)
{
this.eventDelegate.LeapEventNotification("onExit");
}
public override void OnDisconnect(Controller controller)
{
this.eventDelegate.LeapEventNotification("onDisconnect");
}
}
}