Onvif Camera get current position - c#

I have a simple application which allows me controlling PTZCameras.
My problem is getting the current camera position.
To do this I've used var position = ptzClient.GetStatus(profile.token).Position instruction.
If I set a new preset (using SetPreset method), without moving the camera device, its position results different from status.Position.
I think that the actual camera position is the preset.PTZPosition and not status.Position value.
How can I know the true camera value? And which position is status.Position?
Thank you.

Related

How to move a Player in Vector3 using GPS coordinates? [Unity]

I need to develop a Unity Android APP to help in agricultural guidance and I am facing some very especific GPS problems, let me just explain the project to you.
It needs to use accurate GPS data to guide you on the fields
It won't be able to connect the ethernet, I just get the Latitude
and Longitude, the map is just a infinite ground plane (already
made) not some real world map.
The "player" (tractor, machine,...) needs to move on the Unity
space (not the ground texture, the player itself) because I need to draw a Trail
Renderer for my planting path (already made).
So I have a very specific situation where every API I found moves the ground texture instead of the player object. I need to transform my Latitude and Longitude changes (movement) into Unity space movement, I need to accurately move (transform.Translate) my player on the Vector3 coordinates every time the GPS coordinates changes.
This code is about what I have right now.
//so in the Update method
if (newLat != lastLat || newLong != lastLong){
//what do I do here?
EDIT 1:
This guy has the same question as mine on an old post, but got no response.
After reading this code, I think you can just get the latitude and the longitude and set the position of an object, not move.
By that I mean something like this:
// Get the GPS values (I'm not sure if you can do it like this, I copied it from the code you linked)
latitude = Input.location.lastData.latitude;
longitude = Input.location.lastData.longitude;
// Set the position of a GameObject using the GPS values
transform.position = new Vector3(latitude , 0, longitude);

Pinch and rotate around a point using MRTK and Hololens 1

I'm trying to rotate a beam/cuboid around a pivot using MRTK, Unity, and the Hololens 1 when you're doing the pinch and hold gesture. The beam should remain in place once you've let go of the pinch.
My initial thoughts were to get the cartesian coordinates of the pinch and based on their position relative to the pivot, have the beam rotate by however many degrees needed. E.g. the hand position while pinching is (1,1,0), and the pivot position is (0,0,0). Thus, the beam should be rotated at 45 deg in the XY plane (we ignore the z components). I'm not sure how to go about doing this as the documentation seems to indicate that the only way to get the coordinates of the hand/pinch only works for the Hololens 2. (https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/Input/HandTracking.html#hand-tracking-events & https://microsoft.github.io/MixedRealityToolkit-Unity/api/Microsoft.MixedReality.Toolkit.Input.IMixedRealityHand.html#Microsoft_MixedReality_Toolkit_Input_IMixedRealityHand_TryGetJoint_).
Does anyone know how to go about doing this or at least point me in the right direction (tutorials/code/assets would be much appreciated!)
Thank you!
I'm not sure how to go about doing this as the documentation seems to indicate that the only way to get the coordinates of the hand/pinch only works for the Hololens 2
Yes, HoloLens1 does not support hand tracking, such as touching holograms directly with your hands or pointing and committing with hands. It is recommended that you try to use the interaction model Gaze and commit, so that you can easily get the position of GGVPointer.
Pinch to rotate interaction can be achieved by adding the ManipulationHandler component from MRTK to your cube. The component can be configured to allow two hand manipulation like this.
I'm not sure how to go about doing this as the documentation seems to indicate that the only way to get the coordinates of the hand/pinch only works for the Hololens 2.
There are a few ways to query pointer position. The code below should return the Right GGVPointer position for the hololens.
Vector3 pos;
GGVPointer pointer = PointerUtils.GetPointer<GGVPointer>(Handedness.Right);
if(pointer != null)
{
pos = pointer.Position;
}
In case you just want to rotate the Object around its center,you can use the Boundingbox Component. It creates handles that can be pinched and moved to rotate an object. you can disable the axis you don't want. It works even on the HoloLens 1.

hololens setParent position changes camera lens

I am working on using the Hololens Lens Toolkit Master.
The problem is that when you set the SetParent of the lens camera, the camera position of the lens becomes the same as the position of the parent.
For example, if A's position is 0, 0, 0 and B's position is 0, 0, 4, then A.SetParent(B.Transform) would make A's position be 0, 0, -4.
This is also true on Unity Editor.
However, if you build on hololens and run A.SetParent(B.Transform), the position of A will be 0, 0, 4.
I have no idea why this happens ...
I want 0, 0, -4 !!
Generally speaking the parent of the main Camera is the scene itself, you cannot go higher, so the parent is the camera, unless your camera is inside another game object. Also remember too, that with the Hololens, the camera is the stable position everything else needs to move in relation to the camera, not the other way around.
Update: So the main camera in hololens applications is like the character camera in a first person shooter, however its not the camera that moves its the world and the application is not in control of the main camera, in an FPS, you control the character either with a controller, or keyboard. The difference here is that the main camera is controlled by the hololens, 0,0,0,0 is the fixed main camera point and never changes, what happens is that the detection cameras in the hololens update position based on spatial mapping routines in the device, so changes to the position of the main camera will have unexpected results. If you want to change the point of view, I would recommend that you create a new camera and transfer the view to the new camera and move that camera, and the revert back to the main camera when you want to switch it back. This new camera cannot be a child of the main camera. One caveat is that I have never tried this, and is offered as a possible solution, I do not know if it will work or not.
There are two overloads for the SetParent function:
SetParent(Transform parent)
SetParent(Transform parent, bool worldPositionStays);
The first one uses true for the parameter as default. Use the second function and pass false to it to force the object use its location position when setting its parent.
A.SetParent(B.Transform, false);

Get second camera from camera.main property

I have two camera with "MainCamera" tag in a scene.
using this line of code
camera.main.transform.name
I am getting camera name but the problem is, it is only showing one camera name (which is fine) No matter what is depth or order of both main cameras in hierarchy.
How to get only second camera instead the one it is showing!
I only want to use camera.main property and nothing else option.
Camera is nothing but a GameObject with a Camera component attached. So it is very simple to get all instances of the camera:
var cameras = FindObjectsOfType(typeof(Camera));
foreach (Camera camera in cameras)
Debug.Log (camera.name);
In case you want to access the camera inside a rendering method (OnPreRender, OnPostRender, ...), you can access the camera currently rendering via Camera.current.
Other than that, there is no way to get a "second main" camera. Camera.main, will always return the first enabled main camera. You have to go with David's solution.

How to automatically change kinect sensor angle?

Is it possible to change the elevation angle of the kinect motor automatically?
I mean, till now I have this code (c#):
private void CameraAngleSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
int angle = (int)CameraAngleSlider.Value;
KinectSensorManager.ElevationAngle = angle;
}
and I change the angle manually using a slider called CameraAngleSlider.
Just an example: I would imagine that when the kinect start session, I place in front of the kinect and the sensor tries to adjust the angle related to my position.
This should be perfectly possible, however you will have to program this manually and take into account that the adjustment is not very fast. Also the kinect sensors don't push any data while it is adjusting its angle.
You have 2 situations:
1) the skeleton is already being tracked
=> move the angle up when the head is too close to the top of the screen
=> move the angle down when the head is under half the screen heigth
2) no skeleton being tracked
=> you will have to guess.. I'd suggest moving the angle up and down untill you get a tracked skeleton (and abort after a few tries so it doens't just keep adjusting)
There is no flag or function you can set on the Kinect to have it seek out the best position for tracking, based on player position. The Kinect does detect clipping and can be queried as to if a portion of the player is out of the FOV.
The two functions that will allow you to detect clipping of the skeleton are:
FrameEdges Enumeration
Skeleton.ClippedEdges
Depending on how your application is operation you can monitor either one of these and, when clipping of the Skeleton is detected, adjust the KinectSensor.ElevationAngle accordingly.

Categories

Resources