When utilising a Tango what would I use, callbacks or otherwise to detect when the devise has localised to a previously loaded ADF?
This is mainly for UI purposes in conjunction with Tango UX, telling a user to walk around an environment.
Localization may be detected when your TangoPoseData with a frame of ADF comes back valid.
Look at the Tango Java examples of AreaLearningActivity with this simplified logic:
//tell tango to provide pose for ADF
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
TangoPoseData.COORDINATE_FRAME_DEVICE));
//register a listener for the frames chosen
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
//listens for updates from tango pose
public void onPoseAvailable(TangoPoseData pose) {
//base frame of ADF provides coordinates relative to the origin of the ADF
if (pose.baseFrame == TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION
&& pose.targetFrame == TangoPoseData.COORDINATE_FRAME_DEVICE)
//if the status is valid then localization has succeeded
if(pose.statusCode == TangoPoseData.POSE_VALID){
Log.i(TAG,"Successfully localized with ADF");
}
}
}
Your config must indicate which ADF is of interest:
config.putString(TangoConfig.KEY_STRING_AREADESCRIPTION,adfId);
This process is not easily observed from the code, but I discovered it debugging the AreaLearningActivity example. The Java API would benefit from a higher level of abstraction making the common scenario you requested more obvious and easier to use:
TangoLocalizer.builder().register(myListener).adfId(myAdfId).build();
In Unity3D, you can use pose.status_code inside OnTangoPoseAvailable(TangoPoseData) for checking the checking the status (VALID/INVALID) of pose w.r.t. the coordinate frame pair defined.
For Device Localization you need to set targetFrame as TANGO_COORDINATE_FRAME_DEVICE AND baseFrame as TANGO_COORDINATE_FRAME_AREA_DESCRIPTION
public void OnTangoPoseAvailable(TangoPoseData pose)
{
// Define the frame-pair
if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION
&& pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE)
{
// Check if the pose is VALID or INVALID
if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID)
{
////......if pose is VALID
}
else
{
////......if pose is INVALID
}
}
}
You also need to load the ADF using m_tangoApplication.Startup (m_selectedADF); as well.
Related
I am trying to add support for per-directory viewing settings to the Thunar file browser of the Xfce desktop. So for example if a user chooses to view the contents of a directory as a list rather than as a grid of icons, this setting is remembered for that directory and will be used whenever that directory is viewed.
Now Thunar is built on GLib, and the mechanism we have chosen to use to implement this is to store metadata using GFile attributes, using methods like g_file_set_attributes_async to store
keys with names such as "metadata::thunar-view-type". The per-directory feature can be turned on or off by the user via a checkbox in a preferences dialog. My knowledge of GIO and GLib is pretty limited, but I have now managed to get this all working as desired (you can see my merge request here if you are interested).
Now as I understand it, the functionality that I am using here relies on something called "GVfs metadata", and as I understand it this might not be available on all systems. On systems where GVfs metadata is not available, I want to turn this functionality off and in particular make the checkbox in the preferences dialog insensitive (i.e. greyed out). Thus I need to write a function to detect if gvfs metadata support is available, by which I mean whether I can use functions like g_file_set_attributes_async to successfully save metadata so that it will be available in future.
Thunar is written in C, so this function needs to be written in C using the C API for GLib, GIO, etc.
The function I have come up with (from much reading of API documentation, modifying code scraps I have found, and experimentation) is as follows.
gboolean
thunar_g_vfs_metadata_is_supported (void)
{
GDBusMessage *send, *reply;
GDBusConnection *conn;
GVariant *v1, *v2;
GError *error = NULL;
const gchar **service_names;
gboolean metadata_found;
/* connect to the session bus */
conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
/* check that the connection was opened sucessfully */
if (error != NULL)
{
g_error_free (error);
return FALSE;
}
/* create the message to send to list the available services */
send = g_dbus_message_new_method_call ("org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"ListNames");
/* send the message and wait for the reply */
reply = g_dbus_connection_send_message_with_reply_sync (conn, send, G_DBUS_SEND_MESSAGE_FLAGS_NONE,
-1, NULL, NULL, &error);
/* release the connection and the sent message */
g_object_unref (send);
g_object_unref (conn);
/* check if we got a sucessful reply */
if (error != NULL)
{
g_error_free (error);
return FALSE;
}
/* extract the GVariant with the array of strings describing the available services */
v1 = g_dbus_message_get_body (reply); /* v1 belongs to reply and must not be freed */
if (v1 == NULL || !g_variant_is_container (v1) || g_variant_n_children (v1) < 1)
{
g_object_unref (reply);
return FALSE;
}
v2 = g_variant_get_child_value (v1, 0);
g_object_unref (reply);
/* check that the GVariant we have been given does contain an array of strings */
if (!g_variant_is_of_type (v2, G_VARIANT_TYPE_STRING_ARRAY))
{
g_variant_unref (v2);
return FALSE;
}
/* search through the list of service names to see if gvfs metadata is present */
metadata_found = FALSE;
service_names = g_variant_get_strv (v2, NULL);
for (int i=0; service_names[i] != NULL; i++)
if (g_strcmp0 (service_names[i], "org.gtk.vfs.Metadata") == 0)
metadata_found = TRUE;
g_free (service_names);
g_variant_unref (v2);
return metadata_found;
}
As you can see, this function uses DBus to query service names to see if the necessary service is available. Now, as far as I have been able to test it, this function works as I want it to. However, during a code review it has been questioned whether this can be done without relying on DBus (which might itself not be available even though GVfs metadata is).
Thus (at last!) my question: what is the best (i.e. most robust and accurate) way to test for GVfs metadata support via the C API for GLib, GIO, etc?. As I said above, by "GVfs metadata support" I mean "can I use functions like g_file_set_attributes_async to successfully save metadata so that it will be available in future?".
One method I have considered is looking at the list of running processes for the name "gvfsd-metadata", but that seems a bit kludgy to me.
Also, as mentioned above I am very much a novice with these technologies, so I is absolutely possible that I have misunderstood stuff here, so if you spot any errors in the assertions I have made above, please let me know.
Thanks!
(And yes, usual story, I'm a long time reader of SO & co, but a first time asker, so please feel free to edit or let me know if I've done something wrong/bad)
Call g_file_query_settable_attributes() and g_file_query_writable_namespaces() on the GFile, as described in the GFileInfo documentation:
However, not all attributes can be changed in the file. For instance, the actual size of a file cannot be changed via g_file_info_set_size(). You may call g_file_query_settable_attributes() and g_file_query_writable_namespaces() to discover the settable attributes of a particular file at runtime.
When i enable virtual stick control and tries to update the control values using Virtual stick control it updates values but remote controller get disabled (Unable to send data without Virtual stick mode enabled ).Both virtual stick and remote controller commands not get transmitted .
As noted above, enabling virtual stick will disable direct stick control but you can "simulate" stick control using the hardwareStatus. HardwareStatus returns the position of each stick as the user moves it and the information is reported to the app.
Using the above method you could coordinate your app's use of virtual stick with the user's movement of the physical sticks and send virtual stick commands that include the user's controls.
This is expected behavior. They are mutually exclusive. When you want to control aircraft through virtual sticks the remote controller sticks are disabled. But if you want to take control of aircraft change the mode of remotecontroller
This is a design decision by DJI (a very dangerous one in my opinion).
Note that this does not mean the user will always be able to use RC
sticks to control the aircraft; for example, in F mode (P mode for
A3/N3 FW > 1.5.0.0) the sticks are unavailable when the SDK is
executing movement control. The correct way to assert the RC's control
precedence is to make sure the above conditions for API control are
unmet - usually the easiest way to do so is to switch the RC out of F
mode into P or A mode. For A3/N3 FW > 1.5.0.0, please see mode switch
changes.
http://developer.dji.com/onboard-sdk/documentation/introduction/things-to-know.html
I solved that toggling virtual sticks on/off when send FlightControlData:
private void toggleVirtualStick(boolean b, String s) {
getAircraftInstance().getFlightController().setVirtualStickModeEnabled(b, new CommonCallbacks.CompletionCallback() {
#Override
public void onResult(DJIError djiError) {
if (djiError == null) {
((Switch)findViewById(R.id.virtualStick)).setChecked(b);
} else {
showToast(djiError.getErrorCode() + " - " + djiError.getDescription());
}
}
})
I'm actually tryin to place SharpDX Window in Winforms Window like in the following video:
http://www.youtube.com/watch?v=g-JupOxwB-k
In SharpDX this method doesn't work.Can anyone tell me how to EASILY do this ?
don't think of it as putting a sharpDX window into a winforms window.
instead think of it as how to output SharpDX to the windows handle (sorta)
the key is in the SharpDX.DXGI.SwapChain. when creating this you will need a SwapChainDescription
I like to create mine like
SwapChainDescription scd = new SwapChainDescription()
{
//set other fields
OutputHandle = yourform.Handle,
//set other fields
};
Handle
SwapChainDescription
so when you call SwapChain.Present() it will render to the form.
this is the basic way to do it with straight SharpDX and not the toolkit stuff
EDIT 04222019 LINKS DO NOT WORK --- 01052022 Link fixed
if you want to use the toolkit's GraphicsDevice you will have to set the Presenter property. in almost the same way you set the window handle in the presentation parameters.
https://github.com/sharpdx/Toolkit/tree/master/Documentation
also the toolkit has the RenderForm which plays nice with the Game class
04222019
EDIT (DirectX Example)
here is an example using straight SharpDX (No Toolkit). for complete examples you should refer to the github examples HERE
As stated above all you need to do to render to a WindowsForm window is pass the Handle to the SwapChain
visual studio 2012
add the references: (all other references are default winforms project references)
some using statements to make things easier:
namespace YourNameSpaceHere
{
using Device = SharpDX.Direct3D11.Device;
using Buffer = SharpDX.Direct3D11.Buffer;
...the rest of the application
}
the Form class: here we make the device, swap chain, render target , and render target view a variable of the Form class we are declaring
public partial class Form1 : Form //default vs2012 declaration
{
Device d; //Direct311
SwapChain sc; //DXGI
Texture2D target; //Direct3D11
RenderTargetView targetveiw;//DIrect3D11
...the rest of the form
}
Initializing the Device and SwapChain: this is what works for me on my system. if you have problems than you need to research your specific implementation and hardware. DirectX (and by extension SharpDX) has methods by which you can detect what the hardware will support.
the main code Example:
using System;
using System.ComponentModel;//needed to overide OnClosing
//I removed useless usings
using System.Windows.Forms;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX;
namespace WindowsFormsApplication2
{
using Device = SharpDX.Direct3D11.Device;
using Buffer = SharpDX.Direct3D11.Buffer;
public partial class Form1 : Form
{
Device d;
SwapChain sc;
Texture2D target;
RenderTargetView targetveiw;
public Form1()
{
InitializeComponent();
SwapChainDescription scd = new SwapChainDescription()
{
BufferCount = 1, //how many buffers are used for writing. it's recommended to have at least 2 buffers but this is an example
Flags = SwapChainFlags.None,
IsWindowed = true, //it's windowed
ModeDescription = new ModeDescription(
this.ClientSize.Width, //windows veiwable width
this.ClientSize.Height, //windows veiwable height
new Rational(60,1), //refresh rate
Format.R8G8B8A8_UNorm), //pixel format, you should resreach this for your specific implementation
OutputHandle = this.Handle, //the magic
SampleDescription = new SampleDescription(1, 0), //the first number is how many samples to take, anything above one is multisampling.
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
Device.CreateWithSwapChain(
SharpDX.Direct3D.DriverType.Hardware,//hardware if you have a graphics card otherwise you can use software
DeviceCreationFlags.Debug, //helps debuging don't use this for release verion
scd, //the swapchain description made above
out d, out sc //our directx objects
);
target = Texture2D.FromSwapChain<Texture2D>(sc, 0);
targetveiw = new RenderTargetView(d, target);
d.ImmediateContext.OutputMerger.SetRenderTargets(targetveiw);
}
protected override void OnClosing(CancelEventArgs e)
{
//dipose of all objects
d.Dispose();
sc.Dispose();
target.Dispose();
targetveiw.Dispose();
base.OnClosing(e);
}
protected override void OnPaint(PaintEventArgs e)
{
//I am rendering here for this example
//normally I use a seperate thread to call Draw() and Present() in a loop
d.ImmediateContext.ClearRenderTargetView(targetveiw, Color.CornflowerBlue);//Color to make it look like default XNA project output.
sc.Present(0, PresentFlags.None);
base.OnPaint(e);
}
}
}
this is meant to get you started with using DirectX using ShaprDX in a managed environment, specifically C# on Windows. there is much much more you will need to get something real off the ground. and this is meant as the gateway to rendering on a Winforms window using SharpDX. I don't explain things like vertex/index buffers or rendering Textures/Sprites. because it is out of scope for the question.
Is there any way to conditionally import libraries / code based on environment flags or target platforms in Dart? I'm trying to switch out between dart:io's ZLibDecoder / ZLibEncoder classes and zlib.js based on the target platform.
There is an article that describes how to create a unified interface, but I'm unable to visualize that technique not creating duplicate code and redundant tests to test that duplicate code. game_loop employs this technique, but uses separate classes (GameLoopHtml and GameLoopIsolate) that don't seem to share anything.
My code looks a bit like this:
class Parser {
Layer parse(String data) {
List<int> rawBytes = /* ... */;
/* stuff you don't care about */
return new Layer(_inflateBytes(rawBytes));
}
String _inflateBytes(List<int> bytes) {
// Uses ZLibEncoder on dartvm, zlib.js in browser
}
}
I'd like to avoid duplicating code by having two separate classes -- ParserHtml and ParserServer -- that implement everything identically except for _inflateBytes.
EDIT: concrete example here: https://github.com/radicaled/citadel/blob/master/lib/tilemap/parser.dart. It's a TMX (Tile Map XML) parser.
You could use mirrors (reflection) to solve this problem. The pub package path is using reflection to access dart:io on the standalone VM or dart:html in the browser.
The source is located here. The good thing is, that they use #MirrorsUsed, so only the required classes are included for the mirrors api. In my opinion the code is documented very good, it should be easy to adopt the solution for your code.
Start at the getters _io and _html (stating at line 72), they show that you can load a library without that they are available on your type of the VM. Loading just returns false if the library it isn't available.
/// If we're running in the server-side Dart VM, this will return a
/// [LibraryMirror] that gives access to the `dart:io` library.
///
/// If `dart:io` is not available, this returns null.
LibraryMirror get _io => currentMirrorSystem().libraries[Uri.parse('dart:io')];
// TODO(nweiz): when issue 6490 or 6943 are fixed, make this work under dart2js.
/// If we're running in Dartium, this will return a [LibraryMirror] that gives
/// access to the `dart:html` library.
///
/// If `dart:html` is not available, this returns null.
LibraryMirror get _html =>
currentMirrorSystem().libraries[Uri.parse('dart:html')];
Later you can use mirrors to invoke methods or getters. See the getter current (starting at line 86) for an example implementation.
/// Gets the path to the current working directory.
///
/// In the browser, this means the current URL. When using dart2js, this
/// currently returns `.` due to technical constraints. In the future, it will
/// return the current URL.
String get current {
if (_io != null) {
return _io.classes[#Directory].getField(#current).reflectee.path;
} else if (_html != null) {
return _html.getField(#window).reflectee.location.href;
} else {
return '.';
}
}
As you see in the comments, this only works in the Dart VM at the moment. After issue 6490 is solved, it should work in Dart2Js, too. This may means that this solution isn't applicable for you at the moment, but would be a solution later.
The issue 6943 could also be helpful, but describes another solution that is not implemented yet.
Conditional imports are possible based on the presence of dart:html or dart:io, see for example the import statements of resource_loader.dart in package:resource.
I'm not yet sure how to do an import conditional on being on the Flutter platform.
I have an EMGU (openCV wrapper) program that subtracts the background from
a camera feed and extracts nice clean blobs.
Now I need something that will track these blobs and assign them with IDs.
Any suggestions/libraries ?
Thanks,
SW
well if you have multiple objects that you would like to track you could try a Particle Filter.
Particle filters basically "disposes" particles on the image which each have a certain weight. In each time step these weights are then updated by comparing them with the actual measured value of the object at that time. Particles with high weight will then dispose more particles in its direction (with adding a slight random part on the direction) for the next time step.
After a few time steps the particles will then group around the objects measured position. That's why this method is sometimes also called Survival of the fittest method...
So this whole thing builds a circle:
Initialization ----> Sampling
> \
/ >
Updating Prediction
< /
\ <
Association
So this provides a good method of tracking objects in a given scene. One way to do multi-object tracking would be to use this one particle filter on all the objects, which would work, but has disadvantages when you try to give IDs to the objects and also when the objects cross each other since the particle clouds might lose one object and follow another one.
To solve this you could try a Mixture-Particle-Filter (by Vermaak et al. [2003]). This one tracks each of the objects by an individual Particle filter (with of course less necessary particles).
A good paper on that can be found here: http://www.springerlink.com/content/qn4704415gx65315/
(I can also supply you with several other stuff on that if you like and if you speak German I can even give you a presentation I held about that in my university a while ago)
EDIT:
Forgot to mention: Since you try to do this in OpenCV: as far as I know there is an implementation of the Condensation algorithm (the first one where you use one particle filter on the whole image) is part of the OpenCV distribution, though it might be outdated a bit. There might be newer ways of the particle filter in OpenCV directly but if not you will find a lot of results on Google if you look for OpenCV and particle filters
Hope that helps... if not, please keep asking...
You could simply adapt one of the EMGU CV examples that makes use of
VideoSurveillance namespace:
public partial class VideoSurveilance : Form
{
private static MCvFont _font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
private static Capture _cameraCapture;
private static BlobTrackerAuto<Bgr> _tracker;
private static IBGFGDetector<Bgr> _detector;
public VideoSurveilance()
{
InitializeComponent();
Run();
}
void Run()
{
try
{
_cameraCapture = new Capture();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
_detector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.FGD);
_tracker = new BlobTrackerAuto<Bgr>();
Application.Idle += ProcessFrame;
}
void ProcessFrame(object sender, EventArgs e)
{
Image<Bgr, Byte> frame = _cameraCapture.QueryFrame();
frame._SmoothGaussian(3); //filter out noises
#region use the background code book model to find the forground mask
_detector.Update(frame);
Image<Gray, Byte> forgroundMask = _detector.ForgroundMask;
#endregion
_tracker.Process(frame, forgroundMask);
foreach (MCvBlob blob in _tracker)
{
frame.Draw(Rectangle.Round(blob), new Bgr(255.0, 255.0, 255.0), 2);
frame.Draw(blob.ID.ToString(), ref _font, Point.Round(blob.Center), new Bgr(255.0, 255.0, 255.0));
}
imageBox1.Image = frame;
imageBox2.Image = forgroundMask;
}
}