本文介绍了鼠标点击kinect c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我试着通过点击实现鼠标光标 但我知道在c# 任何人都可以帮助我吗? 使用Microsoft.VisualBasic; 使用System; 使用System.Collections; 使用System.Collections.Generic; 使用System.Data; 使用System.Diagnostics; 使用System.IO; 使用System.Media ; $ 使用Microsoft.Research.Kinect.Nui; 使用Microsoft.Research.Kinect.Audio; 使用Microsoft.Speech.AudioFormat; 使用Microsoft.Speech.Recognition; 使用System.Runtime.InteropServices; 公共类Input_Device_Kinect { [ DllImport(" user32",CharSet = CharSet.Ansi,SetLastError = true,Exac tSpelling = true)] $ //这些声明需要执行鼠标单击和光标移动 private static extern void mouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo); private const MOUSEEVENTF_LEFTDOWN = 0x2; 私有const MOUSEEVENTF_LEFTUP = 0x4; private const MOUSEEVENTF_RIGHTUP = 0x10; private const MOUSEEVENTF_ABSOLUTE = 0x8000; [DllImport(" user32",CharSet = CharSet.Ansi,SetLastError = true,Exact Spelling = true)] private static extern int SetCursorPos(int x,int y) ; $ 私人运行时nui; 私有const字符串RecognizerId =" SR_MS_en-US_Kinect_10.0"; public Input_Device_Kinect() { nui = new Runtime(); nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); $ nui.VideoStream。打开(ImageStreamType.Video,2,ImageResolution.Resolution640x480,ImageType.Color); nui.DepthStream.Open(ImageStreamType.Depth,2,ImageResolution.Resolution320x240,ImageType.DepthAndPlayerIndex); $ //这是骨架部件的事件处理程序 nui.SkeletonFrameReady + = nui_SkeletonFrameReady; $ } private void tracking_stop(object sender,EventArgs e) { nui.Uninitialize(); } private void nui_SkeletonFrameReady(object sender,SkeletonFrameReadyEventArgs e) { SkeletonFrame skeletonFrame = e.SkeletonFrame; int iSkeleton = 0; foreach(skeletonFrame.Skeletons中的SkeletonData数据){ if(SkeletonTrackingState.Tracked == data.TrackingState){ //在这里,您可以使用所需的关节调用此方法。即JoindID.Head,JoindID.HandRight ... //从那里你可以处理这些数据 getBodySegment(data.Joints,JointID.HandLeft,JointID.HandRight ); $ } } } private Point getDisplayPosition(Joint joint) { 返回新点(Screen.PrimaryScreen.Bounds.Width *(joint.Position.X + 1)/ 2 ,Screen.PrimaryScreen.Bounds.Height *(1 - joint.Position.Y)/ 2); } //在这里,您只需使用左手和右手的数据进行进一步处理。我用方法setMyCursor()调用数据为$ //右手为设置光标的位置以及方法performClick()和左手数据。 //如果您发送更多数据(参数),也可以扩展if情况。如果ids(i).ToString.Equals(" Head")则...例如。 私有对象getBodySegment(Microsoft.Research.Kinect.Nui.JointsCollection joint,params JointID [] id) { Point pointRight = default(Point) ; $ for(int i = 0; i< = ids.Length - 1 ; i ++){ //这里我必须把手的代码 if(ids [i] .ToString.Equals(" HandRight")){ Debug.Print("Right Hand Found"); pointRight = getDisplayPositi on(joints(ids [i])); setMyCursor(pointRight.X, pointRight.Y); }否则if(ids [i] .ToString.Equals ("HandLeft")){ Debug.Print(" Left Hand Found" ;); $ Point pointLeft = getDisplayPosition(joints(ids [i])); //这里我们需要右手坐标才能知道在哪里; //执行点击。需要左手的协调按顺序 $ //检索是否应该执行click performClick(pointRight.X,pointRight.Y,pointLeft.X ,pointLeft.Y); } } } //这里我只是设置坐标(在本例中为Y)来设置点击点。在这种情况下,我使用hight。 private void performClick(int pointRX,int pointRY ,int pointLX,int pointLY) { //在这里,您可以将此值(300)调整为适合您需要的值($ b) $ b if(pointLY< 300){ //单击右手位置 Debug.Print(" CLICK #################"); //这里我只是执行一次点击。 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); } } private void setMyCursor(int X,int Y) { //这里我将光标设置为从右手检索的坐标。 SetCursorPos(X,Y); } } b 谢谢 解决方案 你有没有对这个功能进行过搜索?这个区域有很多(主要是我的意思是一大堆)主题。在这里你的同一页面甚至还有一个; http://social.msdn.microsoft .com /论坛/ zh-CN / kinectsdk / thread / 8a36b8c9-e555-4671-87be-6e6d5afff70a 尝试发布那里的Thinker链接。 Hi everyone ,I'm try to implement mouse cursor with clicking but I'm knew in c#And I found c# code but it's for the old version sdk beta to I try to change it but I can'tCan any one help me ?using Microsoft.VisualBasic;using System;using System.Collections;using System.Collections.Generic;using System.Data;using System.Diagnostics;using System.IO;using System.Media;using Microsoft.Research.Kinect.Nui;using Microsoft.Research.Kinect.Audio;using Microsoft.Speech.AudioFormat;using Microsoft.Speech.Recognition;using System.Runtime.InteropServices;public class Input_Device_Kinect{[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]//These declarations are needed to perform the mouse clicks and cursor movementsprivate static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);private const MOUSEEVENTF_LEFTDOWN = 0x2;private const MOUSEEVENTF_LEFTUP = 0x4;private const MOUSEEVENTF_RIGHTUP = 0x10;private const MOUSEEVENTF_ABSOLUTE = 0x8000;[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]private static extern int SetCursorPos(int x, int y);private Runtime nui;private const string RecognizerId = "SR_MS_en-US_Kinect_10.0";public Input_Device_Kinect(){nui = new Runtime();nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);//This is an event handler for the skeleton partsnui.SkeletonFrameReady += nui_SkeletonFrameReady;}private void tracking_stop(object sender, EventArgs e){nui.Uninitialize();}private void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e){SkeletonFrame skeletonFrame = e.SkeletonFrame;int iSkeleton = 0;foreach (SkeletonData data in skeletonFrame.Skeletons) {if (SkeletonTrackingState.Tracked == data.TrackingState) {//Here you call this method with the Joints you want. i.e. JoindID.Head, JoindID.HandRight...//From there you can work with these datagetBodySegment(data.Joints, JointID.HandLeft, JointID.HandRight);}}}private Point getDisplayPosition(Joint joint){return new Point(Screen.PrimaryScreen.Bounds.Width * (joint.Position.X + 1) / 2, Screen.PrimaryScreen.Bounds.Height * (1 - joint.Position.Y) / 2);}//Here you simply use the data of the left and right hand for further processing. I call the method setMyCursor() with the data of//the right hand to set the position of the cursor and also the method performClick() with the data of the left hand.//Here you can also extend the if cases if you send more data(parameters). If ids(i).ToString.Equals("Head") then...for instance.private object getBodySegment(Microsoft.Research.Kinect.Nui.JointsCollection joints, params JointID[] ids){Point pointRight = default(Point);for (int i = 0; i <= ids.Length - 1; i++) {//Here i have to put the code for the handif (ids[i].ToString.Equals("HandRight")) {Debug.Print("Right Hand Found");pointRight = getDisplayPosition(joints(ids[i]));setMyCursor(pointRight.X, pointRight.Y);} else if (ids[i].ToString.Equals("HandLeft")) {Debug.Print("Left Hand Found");Point pointLeft = getDisplayPosition(joints(ids[i]));//Here we need the coordinates of the right hand in order to know where to //perform the click. The coordinated of the left hand are needed in order //to retrieve if a click should be performedperformClick(pointRight.X, pointRight.Y, pointLeft.X, pointLeft.Y);}}}//Here i simply set the coordinates (in this case Y) to set the click points. In this case i use the hight.private void performClick(int pointRX, int pointRY, int pointLX, int pointLY){//Here you can adjust this value (300) to the one that is suitable for your needsif (pointLY < 300) {//click at position of right handDebug.Print("CLICK #################");//Here i simply perform a click.mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);}}private void setMyCursor(int X, int Y){//Here i set the cursor to the coordinates retrieved from the right hand.SetCursorPos(X, Y);}}thanks 解决方案 Have you done a search on this function? There's a bunch (and by bunch I mean an incredibly large amount) of topics on this area. There's even one on the same page as yours here;http://social.msdn.microsoft.com/Forums/en-US/kinectsdk/thread/8a36b8c9-e555-4671-87be-6e6d5afff70aTry the links The Thinker posted there. 这篇关于鼠标点击kinect c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 19:14