Kinect V2 - Loading XEF files recorded in Kinect Studio, accessing the Color and Depth frames - kinect-sdk

I need to get the Color and Depth frames from an XEF file recorded using Kinect Studio.
My code for accessing the Color and Depth frames when using the Kinect directly looks like this:
_sensor = KinectSensor.GetDefault();
if (_sensor != null)
{
_sensor.Open();
_reader = _sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Infrared | FrameSourceTypes.Body);
_reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
_coordinateMapper = _sensor.CoordinateMapper;
}
In private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) I do my magic, which works.
Now how do I go about that using a pre-recorded XEF file?
I got that I can load an XEF file like this:
var kStudioClient = KStudio.CreateClient();
var eventFile = kStudioClient.OpenEventFile(#"D:\Kinect Studio Recordings\20170922_083134_00.xef");
But how can I get a MultiSourceFrame from that?
Any help is greatly appreciated! Thanks!

You are on the right track with the KStudioClient API. If you haven't implemented it yourself already, there is also a KStudioPlayback class you should use to play back XEF clips asynchronously. I will not explain and give you exact code how to playback at this stage - the API is very easy to understand. Correct usage of this class will issue MultiSourceFrameArrived events automatically, so you do now need to change the way you handle them.
Here is everything you need to know to get up to speed with the KStudioPlayback class - KStudioPlayback class API. If you need code samples, post a comment, and I will get back to you.

Related

Unity A* graph won't scale with canvas

I am using the A* graph package that I found here.
https://arongranberg.com/astar/download
it all works well in scene view and I was able to set the graph to treat walls like obstacles.
However once I start the game the canvas scales and the graph's nodes no longer align with the walls.
this is really messing up my path finding. If anyone has any ideas how to fix this that would be much appreciated. I tried parenting the graph to the canvas but it still doesn't scale.
Kind regards
For anyone struggling with this what we did is edited the script of the A* code, in the update function we just got it to rescan once. This means that once the game started and all the scaling had taken place the graph re adjusted its bounds. This is probably not the most proper way but it only took four lines and worked for us.
private bool scanAgain = true;
private void Update () {
// This class uses the [ExecuteInEditMode] attribute
// So Update is called even when not playing
// Don't do anything when not in play mode
if (!Application.isPlaying) return;
navmeshUpdates.Update();
// Execute blocking actions such as graph updates
// when not scanning
if (!isScanning) {
PerformBlockingActions();
}
// Calculates paths when not using multithreading
pathProcessor.TickNonMultithreaded();
// Return calculated paths
pathReturnQueue.ReturnPaths(true);
if (scanAgain)
{
Scan();
scanAgain = false;
}

Change motion using script in Unity Editor

Hi how do we change motion in an AnimatorController using script in Unity Editor?
The red highlight is the one I'd like to change, but using script
My use case is to copy animations from one object, process the animation e.g. adding offset rotation, then add to another object. Since my object has many child objects, I need to create a script to automate this.
Changing the AnimatorController via editor scripts is always quite tricky!
First of all you need to have your AnimationClip from somewhere
// somewhere get the AnimationClip from
var clip = new AnimationClip();
Then you will have to cast the runtimeAnimatorController to an AnimatorController which is only available in the Editor! (put using UnityEditor; at the top of the script!)
var controller = (AnimatorController)animator.runtimeAnimatorController;
Now you can get all its information. In your case you can probably use the default layer (layers[0]) and its stateMachine and according to your image retrieve the defaultState:
var state = controller.layers[0].stateMachine.defaultState;
or find it using Linq FirstOrdefault (put using System.Linq; at the top of the script) like e.g.
var state = controller.layers[0].stateMachine.states.FirstOrDefault(s => s.state.name.Equals("SwimmingAnim")).state;
if (state == null)
{
Debug.LogError("Couldn't get the state!");
return;
}
Finally assign the AnimationClip to this state using SetStateEffectiveMotion
controller.SetStateEffectiveMotion(state, clip);
Note however that even though you can write individual animation curves for an animation clip using SetCurve unfortunately it is not possible to read them properly so it will be very difficult to do what you want
copy animations from one object, process the animation e.g. adding offset rotation, then add to another object.
You will have to go through AnimationUtility.GetCurveBindings which gets quite complex ;)
Good Luck!

GMap.Net .ToImage() Function Outputting Images With Blank Tiles

The .ToImage() function in GMap.Net does not appear to wait for the map data to be downloaded before the screenshot is taken. This results in images with blank tiles. Is there any existing capability that would allow GMaps to wait until the map is loaded?
I already posted my question on GitHub but haven't gotten a response so far. So any help is appreciated.
VB.NET Code
Private Function TakeBitmapScreenShot() As Image
'''''''''''''''''''''''''''''''''''''''''
'Code to wait until all tiles have loaded
'''''''''''''''''''''''''''''''''''''''''
Return GMapControl.ToImage()
End Function
You can Handle the event (OnTileLoadComplete ) which fires when the tile images completly loaded and then you can take the screenshot
GMapControl1.OnTileLoadComplete += GMapControl1_OnTileLoadComplete;
private void GMapControl1_OnTileLoadComplete(long ElapsedMilliseconds)
{
GMapControl.ToImage();
}
Two of the ways around this are using the TilePrefetcher or even better this code.

How to persist markers using ADF in TangoARPoseController

I am trying to persist markers in an augmented reality game. Here is the gist of what I am doing:
I have my users recording and saving an area to an ADF. Then they drop marker’s into the scene and save out their position data in Unity World coordinates to a text file. I then restart the app, load and localize to the ADF and load the markers.
In order to get this working, I've modified the ARPoseController.cs file in the Unity demo package to use the Area Description as it's base frame. In the _UpdateTransformation method I've swapped out the frame pairs
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
for
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
I've also added some code confirming that I'm successfully localizing to the ADF, but I'm noticing that my markers position in Unity World Space do not position properly relative to real environment.
I can confirm that my markers save and load properly based on START_OF_SERVICE origin so I assume that they are properly serializing and deserializing. What could be causing this? Am I wrong in assuming this should just work by switching the base framepair to Area_Description instead of START_OF_SERVICE?
I had a similar problem getting the AR and ADF integrated, I had to modify the TangoPointCloud to check if you're using an AreaDescription in OnTangoDepthAvailable() and adjust the baseFrame target as required.
i.e.:
if (m_tangoDeltaPoseController.m_useAreaDescriptionPose)
{
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
}
else
{
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
}
That way, the geometry of the point cloud adjusts itself based on the ADF offset instead of from device start.
After that change, when I'm using the sample code for AR to drop markers, it registers the surface properly so I'm placing the markers in the correct spots and orientation. I'm still encountering some flakiness with the markers not adjusting when relocalized though, have to look into the AreaLearningInGameController for loop closure events.
Hope that helps!

CreateJS - Measuring FPS in RAF (requestAnimationFrame) mode

I am using CreateJS in the RAF mode
createjs.Ticker.timingMode = createjs.Ticker.RAF;
How do I integrate with for instance stats.js measure the browser's FPS?
Or is there any different, recommended way to measure the FPS with CreateJS?
Thanks!
You should be able to integrate using the instructions on the stats.js GitHub page
Essentially:
c.Ticker.on("tick", tick, this);
function tick(evt) {
stats.begin();
// do stuff, like stage.update();
stats.end();
}
Alternatively, you could look at Ticker.getMeasuredFPS and Ticker.getMeasuredTickTime.