Detecting a pixel color [duplicate] - android

This question already has answers here:
How to Get Pixel Color in Android
(3 answers)
Closed 2 years ago.
I have a background image in my android studio project containing a little back circle.
What I want is to be able to detect this black circle when a ball move on the screen. Indeed I have a ball moving randomy on this background image, when the ball pass on the black circle, I want to detect it.
Does android have a feature for detecting pixels?
Actually, this black circle represents a hole, and I want to disappear the ball when it pass over the circle. I cannot use collision detection for some reasons

While the question is interesting, it can not be answered in the way you might hope.
To answer the title independently of the question:
Working with the data inside an app is not what Android Studio does.
Android Studio is used to build apps to run on Android, independent of Android Studio.
Inside an app, which can use the functionality provided by the Android system, detecting the color of a pixel in an image is certainly possible. That is a good question to ask at https://android.stackexchange.com/
The problem as you describe it may be very difficult, because you do not make many constraints. As an example, if that should work with any background, there could be black lines, for example.
I will simplify it to what I think you mean:
The app contains an image that contains a black circle that is much smaller than the image.
It also contains a second smaller circle, called the ball, in a different color.
The rest of the image has a third color, uniformly.
The problem you want to solve is: Move the ball, and find whether the smaller circle is completely inside the larger circle.
This is not easy, and quite interesting.
For this, you need to read pixel colors for parts of the image.
But it is unclear what you mean by "detecting pixels", and that may be an important point.
Reading pixels from an image that is part of your application should be simple.
What I described does not use collision detection, and the collision of the circles is irrelevant.

Related

OpenCV detecting hexagon grid on a map

I am trying to detect with OpenCv for Android hexagon fields of a map for a board game. The map looks something like that:
[Sample map]
I tried getting contours using only Value from HSV and I managed to get some of the hexagons, but unfortunately not all of them, I had mostly trouble detecting hexagons that had rivers or roads passing through them.
I managed to get something like that:
[Detected hexagons]
I even tried to make the borders thicker, but it didn't help a lot.
To detect all of the hexagons I thought of averaging the approximite size of the detected and then go on pixel by pixel trying to detect a change in the color (close to black). Later I would like to detect hexagons even on photos of a map, so then I couldn't really rely on the size of other hexagons.
What do you think would be the best way to solve this problem?
EDIT:
Thank you
I just began to implement your idea and it works great, for now i got the horizontal lines:
You deal with regular grid, so you just need to detect just a few, or even one, to compute all others. More will be better, because you'll be able to compute mean, and it will be more accurate. To find contours, it might be useful to find color gradient.

Text in circle in circular motion

I'm trying to create a textview with a circular background such as shown in the image below. I have 6 other circles like this as well which come from user input.
However I run into problems if there are too many characters, it breaks the boundaries of the circle. I want to make the text go in a circular motion around the circle if the text is more than lets say 10 characters like this.
I've read other people have the same problem and the answers revolved around creating custom views. I am not that experienced with Java yet so if anyone can guide me through this I would really appreciate it.

OpenCV android : Hough transform rectangle recognition with image with multiple different sized rectangles

So everyone, my first question on stackoverflow.
I have been working with android and openCV for a month and I was able to successfully implement template Matching. Now, the next task is to detect all the rectangles in the image and get the coordinates (I actually want the color of every rectangle) for research purposes. Kindly help. I tried using Hough transform with canny edge detection but unfortunately it doesn't detect the small rectangles which is the primary concern now.
Thank you!![![Have to detect all the rectangles, small and big ones
So I'm really proud to post an answer to my own question. Hope this helps someone in future. There are obviously a lot of ways to do this but the most accurate way was to use template matching on the main image to find the coordinates of the biggest rectangle and since all the other rectangles are equidistant to the corner points, center of every rectangle can be found which gives the desired colors.
The thin strip in the middle was also recognized by template matching and then a gradient operator represented the various rectangles, every peak in the gradient represents the rectangles.
Kindly comment for code. For research purposes I cannot post to anonymous.

Red eye removal android

I want to implement red eye removal application on android. Is there any api or built in android method to do this? If no then please tell me how can we detect eyes from image? I know how to remove red color but Im having difficulty in detecting eyes from image.
Use the OpenCV to detect the eyes and then in the circular region where you expect the pupils to be, take the pixel value and set the Red value to, say, 20% of its original value while leaving the Green and Blue channels untouched.
There is also the FaceDetector.findFaces() which works for Bitmaps. However, it will just give you a Rectangle of the Face. But it should be easier to search in that rectangle for red-saturated pixels and desaturate the color as Alexander suggested. But this way you don't necessarly need another library.

How do I build a graphical needle gauge UI widget in Android?

I need a graphical needle gauge (like a speedometer etc) for my app but such a UI widget is not part of the SDK so I probably have to create it myself.
My idea is to have the background with the tickmarks and coloured fields (green, yellow, red) as one bitmap and the needle as another bitmap drawn on top of the background, but rotated in the appropriate angle.
In my book, Professional Android 2 Application Development, there is a somewhat similar example with a compass rose, although that one is drawn using line graphics, not pre-fabricated images like I will have to use to get the desired look.
However, in the compass example the whole canvas is rotated before drawing the tick marks. I cannot use this approach as it will also rotate the gauge background. So I need to somehow rotate the needle image (which should be transparent) before superimposing it. But I don't know how to do accomplish this.
Can anyone lead me in the right direction on how to proceed with the needle gauge? Also, if there is a better way to build the meter than sketched above, please let me know.
You can divide your guage into different layers. One for background, one for tick marks. Layer for tick marks can be rotated to draw marks and when turned back and combined with 'background' layer.
You can see the following example with layer technique described above: http://mindtherobot.com/blog/534/android-ui-making-an-analog-rotary-knob/
P.S. This is not my blog, i've just found this technique there.

Categories

Resources