Android graphics , dynamic view - android

I am looking for help/resource that will help me in bringing up a image as follows in android view.
Image looks like x-y axis graph, with sawtooth waves along x-axis, this is a static image developed using certain tool.
I need help to make a line move, parallel to y-axis (red in color) that waits at origin(0,0) and starts moving along x axis until the sawtooth wave ends.
3.If you imagine this as image, there is a wave on x axis and a red line that moves across wave, which is the noise generated in android mobile.
Concern: How to overlap a static image (wave+x-y axis) with a dynamic image (red line) and make it move as the code runs.
There is a timer that will generate the noise (mute/unmute microphone) and user gets to see it in screen when these interference occurs.
I thank you for spending time to read my post.
Please let me know if there are any redundant info , I will edit my question.

If you subclass view you can draw whatever you want in the onDraw(). You just need to use the provided Canvas.

Related

Android Sceneform Plane Detection and their angles

I am trying to develop an Android app which is trying to draw a perfect line directly in front of me. My reference point is my phone, which means that the line has to parallel to my phone's left side.
I have following issues:
I am using Sceneform, so there is no "onSurfaceCreated" callback.(?)
I assume that the white-dots shows the surface. But, then I think if there is a detected surface then I can place a Shape on it. But is can not happen sometimes. And sometimes, I can place a Shape even if there are no visible white-dots.
When I try to draw a line between the points (0,0,0) to (1,0,0), it is not always parallel to the left side of my phone. I assume that the reason of this is related with the following fact :
angle between the left-bottom corner of the detected surface and the left-top corner is not zero. (If we consider the coordinate system as follows : phone's left side is y-axis, bottom is the x-axis.)And this angle changes each time I reopen the app.
These are more theory questions than the implementation. So, I need someone to prove or disprove, or give me guideline.
1) There isn't method like onSurfaceCreated.
2) Not all the detected planes are covered with white-dots. Is is intended because if all the detected planes are rendered with white-dots, it would confuse the users
3) When you talk about the points(0,0,0) and (1,0,0), is it world position or local position? Whether it is world position or local position, you can not draw a line parallel to your left side of phone in the way you approach.

opencv detect cubes (corners)

Problem that I am trying to solve is to detect cubes and get colours from them. I use live images from camera captured by Android phone. Recognition has to be fast (<1s) Example of a cube:
I also have differently coloured cubes. They can be placed randomly (for example when they touch each other).
I can easily detect one cube, in same cases even two cubes, but the problem is when I have 3 or more and for 2 cubes when they are really close to each other.
Currently processing looks like this:
blur image with Gaussian
convert to hsv and use only s channel
detect edges with Canny
dilate and erode edges
use HoughLinesP to get lines
from lines (I reject too long and too short lines) calculate intersection points and from that get corners of cubes
knowing corners (must be precise) get colours
nothing detected
2 cubes detected (red and orange points are corners and cyan points are intersection points, black lines are detected lines by hough lines)
nothing detected, some lines found
Basically what I need is to find correct corners of the cubes. I tried using Imgproc.goodFeaturesToTrack and Imgproc.cornerHarris, but it finds too many of them and usually not the most important ones.
I also tried using findContours with no success even for two objects. findContours was also crashing my app after minute of running. At some point I tried using Feature Matching + Homography to find matches to a grayscale image of a cube with the one from camera, but results were messy. Also Template Matching didn't give me good results.
Do you have any idea how to make detection more reliable and precise?
Thanks for help

Drawing and storing a user's touch path in libgdx

I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?

Fluid snake animation using images

I want create a snake game in Android using AndEngine. But in my game, the snake won't be controlled by the player. It'll just move in random directions.
I have a snake that can move in random directions. My problem is that I want real-time animation (i.e. the snake shouldn't just move after a delay).
I tried using register modifiers to move the snake, and that works. But the problem is that I have images for each snake's tail element.
If I had just rectangles, I would know how do this, but I'm using more advenced images.
When the snake changes direction, I should have an element connecting different directions (example: right and down).
Is there any algorithm for this? Alternatively, where I can find an open source project that explains this?
It's the same with rectangles. Ideally you wouldn't delete the images for the time of the animation.

Help me optimize this graph animation

I need some help with this simple animation on my Android phone. I'm a newbie with animation and graphics.
I'm graphing accelerometer data as a sliding time series window. As new accelerometer data is read, its data is plotted on the right, pushing previous data to the left, as shown below:
My program is running pretty smoothly, but I would like some help optimizing the animation. Here are my main concerns:
My current implementation reads all the accelerometer data in one thread and keeps the data in a fixed-size FIFO queue to capture the width of the time series window. I then use Timer.scheduleAtFixedRate() to plot out the entire contents of the queue so that the whole graph is re-drawn every 50 milliseconds. Can I improve upon this? Do I really need to re-draw the graph so often like this? In another similar program I've seen, each pixel column is copied to one pixel to the left, rippling down the graph; the newest data's column is drawn on the far-right pixel column. Is this better?
I redraw the legend (in the upper left) in the drawing thread that runs the draw function every 50 milliseconds. Is there any way to "keep" that legend in place instead of having to constantly re-draw it?
Any other help would be appreciated. I have heard of optimizations like double-buffering but am clueless if that would help me.
If the legend and the cross hairs only need to be drawn once, then you should place it into a buffer bitmap. For your graph line maybe try using the Path object to plot the lines. When it gets time to draw the lines just drawLine to the appropriate point and then translate the canvas left appropriately.If

Categories

Resources