Get a (Android.Graphics) Path of a String - android

I cannot find any way to retrieve a Path object representing a string. Does it exist? A list of the necessary points would be enough, but I guess, internally, a path is used.
For example in GDI+ there is:
GraphicsPath p = new GraphicsPath();
p.AddString("string");
From there any point of the "drawn string" can be accessed and modified.
PS: I do not mean drawing a text along a path.

I've spent quite a long time solving this problem (to draw vectorized text in OpenGL) and had to dig deep into libSkia sources. And it turned out pretty simple:
Indeed, canvas uses paths internally and it converts text to vector paths using SkPaint's getTextPath() method. Which is, luckily, exposed at Java side in public API as android.graphics.Paint.getTextPath(). After that, you can read Path back with android.graphics.PathMeasure.
Unfortunately, you can't read exact drawing commands, but you can sample the curve pretty closely using something like bisection.

Related

Android: OpenGL ES: associating information with drawn objects

I have a fairly basic question that I cannot for the life of me find the answer to online (most definitely due to not really knowing what I am looking for).
Suppose I have multiple (for the most part static) objects that are stored inside one VBO and drawn to the screen. Each object will have images and text/external data associated with it. I need to be able to navigate this "map" of objects and on-tap, access the corresponding information.
My question is, what is the best practice when it comes to storing this corresponding data and linking it to its respective drawing? I figured you create a "parallel" array of custom objects that each references its drawing and holds all the data... Although it seems quite elementary and thought there might be a better way. Considering also that there will potentially be thousands of these objects on the "map".
You can Use model class and put all common data intro one entity than use extends. You can use yours custom object who will consider whole VBO or opengles program data. About identity make ID for each elementary object or "draws".
-I understand your problematic. In opengl/es procedural programming is actually on scene.
Remember you are still in android envelopment you can use any java/android methodology.
-When you say "tap" did you mean click? If you so than see "Raycast" thema.
-This is interest file . It is JS not android but you can use same logic methods to make your object based app.
https://github.com/zlatnaspirala/visualjs/blob/master/project/project_instance_webgl2/lib/matrix-world.js
You can see lines like this :
App.scene[squareObject.name] = squareObject;
I have a global object App.scene . I put here all object buffer data. It is a key access but works like array.
I wanna say your idea about arrays is good. But not in parallel order. Procedural part works with no problem you need draw function for each element entity.
Look at draw methods :
https://github.com/zlatnaspirala/visualjs/blob/master/project/project_instance_webgl2/lib/matrix-draws.js
For example one of my draw entity is App.operation.draws.cube function.
I use this method to draw any cube but each cube is uniq object with uniq data inside.

SkobblerMaps Android: How to create navigation log file

I want to simulate a drive using the SKNavigationSettings.SKNavigationType.FILE. Is there an easy way to generate one of these files? I see the Seattle.log in the demo project, and I could just edit some coordinates and make my own however it would be great to simulate a real drive. Also I am not sure what all of the entries are:
"47.655942 -122.137419, 11.000000, 19.000000, 0.000000, 1380803959889470, 03.10.2013 15:39:19" (what are 11.000000, 19.000000, 0.000000?)
Update: I still do not have a way of doing this and I do not understand some of the values (listed above). The file is Seattle.log and it just consists of a bunch of lines like the one above separated by newlines.
You can find the full SDK documentation here.
https://www.developer.skobbler.com/docs/android/3.0.2/index.html
Yes, you can obtain a logging file with data collected from a real drive. You can use the startLoggingPositions(String filePath, SPositionLoggingType positionLoggingType) and public boolean stopLoggingPositions() from the SKPositionLoggingManager class (com.skobbler.ngx.positioner.logging package) to accomplish that. You will obtain a log file (if the positionLoggingType is set to SK_POSITION_LOGGING_TYPE_LOG) similar to Seattle.log at the specified path.
The values stored in the file are (in this order): Latitude, Longitude, Course, Speed, Accuracy, Timestamp.

Set number of keypoints in Android OpenCV

I'm trying to run feature detection on an image using some of the inbuilt OpenCV feature detectors. However, I only want to detect the top/best n features present in the image (lets say 30 for this example). I already have code that will find features and then use them to identify that object in other images, but I can't work out how to restrict the number of keypoints found. I initialise the various detectors/extractors/matchers as below:
private final FeatureDetector mFeatureDetector = FeatureDetector.create(FeatureDetector.ORB);
private final DescriptorExtractor mDescriptorExtractor = descriptorExtractor.create(DescriptorExtractor.ORB);
private final DescriptorMatcher mDescriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
I have tried to find a solution already on SO but the only solutions I can find aren't for the android version of OpenCV. Trying similar methods to these solutions also didn't work.
The only method I can think of that might work is just taking the first 30 features, but I don't think this will work well as they might all be clustered in one part of the image. So I was wondering if anyone knows how the top 30 features can be chosen (if indeed they can). I don't mind which feature detection algorithm the solution is for (MSER, ORB, SIFT, SURF, STAR, GFTT, etc.).
I also require that exactly 30 features be detected each time, so playing with the sensitivity until it's "about right" isn't an option.
EDIT: the reason for needing to find exactly 30 features is that I am going to use them to train my detector. The idea is that I will get 30 features from each of a set of training images and then use the result to then find the object again in a scene. As the training images will be close ups of the object it doesn't matter that the features won't be clustered in one part of the image.
Whilst I haven't been able to find a way of setting the number of keypoints to search for, I have been able to work out how to extract the correct number of keypoints afterwards. Doing this isn't computationally efficient but from the comments I received I don't think doing it before is possible.
My keypoints variable is:
private final MatOfKeyPoint mTargetKeypoints = new MatOfKeyPoint();
After it has been "filled" with features (it seems to stop after 500) the individual features can be extracted by transforming it to an array (where each element of the array is a feature.
mTargetKeypoints.toArray()[0]; //NOTE: Not actual code, used in a print statement
When I print the above the result is:
KeyPoint [pt={82.0, 232.0}, size=31.0, angle=267.77094, response=0.0041551706, octave=0, class_id=-1]
The individual information can then be extracted with the inbuilt Keypoint functions, e.g.:
mTargetKeypoints.toArray()[0].pt.x //Printing outputs x location of feature.
mTargetKeypoints.toArray()[0].response // Printing outputs response of feature.
This SO question indicates that the response indicates "how good" the keypoint is. Thus from here it is relatively simple to pick the best 30 features to use.

How to customize parameters used on renderscript root function?

Background
I'm new to renderscript, and I would like to try some experiments with it (but small ones and not the complex ones we find in the SDK), so I thought of an exercise to try out, which is based on a previous question of mine (using NDK).
What I want to do
In short, I would like to pass a bitmap data to renderscript, and then I would like it to copy the data to another bitmap that has the dimensions opposite to the previous one, so that the second bitmap would be a rotation of the first one.
For illustration:
From this bitmap (width:2 , height:4):
01
23
45
67
I would like it to rotate (counter clock-wise of 90 degrees) to:
1357
0246
The problem
I've noticed that when I try to change the signature of the root function, Eclipse gives me errors about it.
Even making new functions creates new errors. I've even tried the same code written on Google's blog (here ), but I couldn't find out how he got to create the functions he used, and how come I can't change the filter function to have the input and output bitmap arrays.
What can I do in order to customize the parameters I send to renderscript, and use the data inside it?
Is it ok not to use "filter" or "root" functions (API 11 and above)? What can I do in order to have more flexibility about what I can do there?
You are asking a bunch of separate questions here, so I will answer them in order.
1) You want to rotate a non-square bitmap. Unfortunately, the bitmap model for Renderscript won't allow you to do this easily. The reason for this is that that input and output allocations must have the same shape (i.e. same number of dimensions and values of those dimensions, even if the Types are different). In order to get the effect you want, you should use a root function that only has an output allocation of the new shape (i.e. input columns X input rows). You can create an rs_allocation global variable for holding your input bitmap (which you can then create/bind on the Java side). The kernel then merely needs to set the output cell to the result of rsGetElementAt(globalInAlloc, y, x).
2) If you are using API 11, you can't adjust the signature of the root() function (you can pass NULL allocations as input, output on the Java side if you are not using them). You also can't create more than 1 kernel per source file on these older API levels, so you are forced to only have a single "root()" function. If you want to use more kernels per source file, consider targeting a higher API level.

Getting coordinates from Path object (there are no such methods at all)

How do I get coordianates from Path and/or Region objects in Android?
There are no such methods which allow you to do that.
Basically I just need the coordinates of my figure points which my Path object contains.
Maybe I can can accomplish this via Reflection? Any help would be appreciated.
If we look at the source code for Path:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/Path.java?av=f
We can see that the coordinates are not stored on Path and are passed into native calls.
One workaround would be to extend Path and override all relevant methods (lineTo, quadTo, moveTo, etc.) to keep track of the coordinates yourself.
Well. Maybe if you use Path's getBounds method and save result in a rect object, you can access on 'left' and 'top' property field of that object for retrieving x and y coordinates

Categories

Resources