5. Use PowerShell to control Kinect and powershellkinect
This is the first time to use the MarkDown editor to write a blog. I like this kind of editor without any comfortable formats. It is easier to read freely and easily, leaving an unnatural natural section to remember and find a comfortable editor.
This time, we will record the use of Windows 7/win8 built-in PowerShell to control the Kinect and change the tilt angle of the Kinect.
After we installed the Kinect SDK, all the drivers and related function libraries used to control the Kinect were installed in Windows. Therefore, we can directly use Windows built-in PowerShell to perform the most basic control on the successfully connected Kinect.
First, open Powershell, press Windows + R to bring up the running window, enter powershell, and press Enter!
We will find... Something like a command prompt appears to be somewhat low-end... Here, we call up the powershell integrated script environment to look better, be more advanced, and be more convenient. In the command prompt that appears, enter ise and press Enter, we can see the mature Ise interface, and there will be an automatic prompt when we write code.
After the integrated script environment is called up, input the script in Ise. The operation we want to do is: Load Assembly -- start the Kinect -- control the tilt angle of the Kinect -- disable the Kinect.
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Kinect")[Microsoft.Kinect.KinectSensor]::KinectSensors[0].Start()[Microsoft.Kinect.KinectSensor]::KinectSensors[0].ElevationAngle=13[Microsoft.Kinect.KinectSensor]::KinectSensors[0].Stop()
For each line we enter, press enter to make adjustments according to our script. The execution result in Ise is as follows:
When executing the first line of script, you will see that the system response has been loaded with the. NET Component inside GAC (Global Assembly Cache, where the system shares. NET components.
Execute the second line of the script. When the Kinect sensor starts, we can notice that the far left infrared projector of the Kinect starts and emits red light.
Execute the third line of script, and the Kinect will obviously look up 13 degrees.
Execute the fourth line of the script, which corresponds to the second line of the script. After using the script, disable the Kinect to avoid additional waste of system resources and ensure that subsequent program examples run smoothly.
We can also use Powershell to switch the infrared projector function of Kinect for Windows. As we mentioned earlier, this function is not available in Kinect for Xbox.
Here I paste the code and it will not be executed in Ise once again.
[Microsoft.Kinect.KinectSensor]::KinectSensors[0].ForceInfraredEmitterOff=1[Microsoft.Kinect.KinectSensor]::KinectSensors[0].ForceInfraredEmitterOff=0
When ForceInfraredEmitterOff = 1, it is forcibly disabled. If it is equal to 0, the infrared is enabled. Of course, this code should also be executed between the Start () and Stop () methods.
Of course, what PowerShell can do is far more than that, but it cannot be used as the tool we developed. It can only be of great help when debugging and familiarizing ourselves with Kinect.
Note: For details about this series of blog posts, refer to "getting started with Kinect somatosensory programming".
2015.3.21 10: 23
By Mr. Losers