This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Fast Java library for circle recognition
I'm looking for a good Java algorithm/library to recognize a circle in a bitmap, and returns the coördinates of the center of the circle. The circle has one color. (eg. green).
Thanks a lot!
First, I should say that I kind of agree that your question should be closed because it is a duplicate. However, I don't quite like the answer provided since it's overkill for such a simple problem.
I would:
Find all connected green blobs. This is not completely trivial, but not that hard either.
For each blob, find the point with the minimum x-coordinate and the one with the maximum x-coordinate and do the same in y. Then you easily get the dimension of the bounding box for the blob. If the x and y dimensions are different, you don't have a circle. However, you should allow for some small differences since drawing a circle with pixels will result in an imperfect circle.
Finally, if you have a circle, the center of the bounding box is (approximately) the circle's center and the radius is half the bounding box width. You can draw such a circle and see how many of the green pixels fit in/out of your circle. Again, you must allow for some imperfections.
Well, you can try with Neuroph Framework (Java Neural Network Framework).
http://neuroph.sourceforge.net/
Its very good api, but there is a catch. The recognition depends of "brightness" of images you are extracting circle from. You can contact author of this framework, he is phd student at University Of Belgrade, and teaching assistant at Artificall inteligence.
I hope i helped you :)
You could try implementing your own method by analyzing image data with a Radon Transform and scanning the result image for horizontal lines.
Related
I am looking for code or a library call that will let me get the size of a 3D object .obj file in Java. Javagl looked promising but I don't see any. I know the way to get the bounding box comes from analyzing the file itself is to get the difference between max X and min X vertex coordinates of the object(similar for all other axis). Then you can get the center of the model from the bounding box by X size/2 + min X (similar for other axis)
Is there a better way to do this than to read the file itself or do that calculations manually?
I am using Java since I am trying to make an AR application using Android + ARCore.
I'll post this as an answer, though it is by no means complete, simply because it is too large for a comment. This is a rather generalized response - what exact methods you require will depend on the frameworks you use for your rendering (or 3D object processing), in this case ARCore I suppose.
Goal: Find center
If I read you correctly, you intend to find the center of your 3D object. First you need to decide what exactly you mean by "center", because this decides, whether or not you need a bounding box at all.
Some options:
Center of mass: A simple implementation of this is assuming all your vertices have equal weight and calculating an average over them. Disadvantage: If your vertices are not distributed uniformly, then the center will shift to whereever most vertices occur.
Center of an Axis Aligned Bounding Box: In this case you use your world coordinate system or whatever coordinate system you defined your 3D object in and find x_min, y_min, z_min, x_max, y_max, z_max. The center of your AABB is then simply the average of these two points. Disadvantage: Depending on 3D object orientation and dimensions the center of the AABB can be quite a bit off or not even inside the object at all.
Center of an Oriented Bounding Box: However maybe you want to define your bounding box based on the dimensions of your 3D object. This case is similar to AABB, however with AABB your base vectors for your bounding box are aligned with the ones of your world coordinate system. For an OBB you need to find new base vectors, where one is typically parallel to the largest-distance-vector between two points in your 3D object and the other two are orthogonal to it and each other. Once the bounding box is found finding center is the same as with the AABB. Disadvantage: Finding bases is expensive.
Visual explanation of the three options described:
Center of Mass
Axis Aligned Bounding Box
Oriented Bounding Box
Further reading
See answer for information on OBB and AABB
Aligned Bounding Box
Oriented Bounding Box
Stanford paper on OBB calculation
A friend and myself are new to game development, and we had a discussion regarding World Coordinates and Screen Coordinates.
We are following a wonderful online tutorial series for libGDX and they are using a 100 PPM (pixels per meter) scaling factor. If you re-size the screen, the scaling of objects no longer works. My friend is convinced that it is not a problem, and he may be right. But, I'm under the impression that when developing a game, the developers should typically only work with the pre-defined world coordinate system and let the camera transform it to the chosen screen coordinates. I do understand the need for reverse transformations when using mouseclicks, etc. But, the placing and scaling of objects in the world space is my concern.
I would like to reach out to this community for some professional feedback.
Thats one of the bigest problem of almost all Libgdx tutorials. They are great, but the pixel to meter/units conversation is just wrong.
Libgdx offers a great solution for that with Camera and an even better solution with the new Viewport classes (which under the hood work with Camera).
Its is really simple and will solve the problem of different screen sizes/aspect rations.
Just choose a Virtual_Width and Virtual_Height (think about it in meters or similar units).
For exampl, you have humans fighting each other in a 2D platformer game. LEts say our humans are 2m tall, so think about, how much screenspace should one human use? If we say, a human should take 1/10 of the screen space, our virtual height is 10*2=20. Now think about the primary aspect ration you are targeting. Lets say it is 16/9, so you have a virtual width of about 35.
Next, you need to think about what kind of Viewport you want. You sure want to use a Viewport, which supports Virtual_Width and Virtual_Heigth.
You may want a Viewport, which keeps the aspect ratio and fills the rest of the screen (if the screen has different aspect ratio) with black bars (FitViewport) or you may want the Viewport to fill the whole screen by stretching the units (StretchViewport).
Now just create the Viewport with your virtual width and heigth and update it in the resize() method with the given width and height.
Hope it helps.
It's be better name as Units per meter
And when you resize your screen you just set a new projective matrix, so everything works fine )
What you should worry about it's a aspect ratio.
Everything rest is doesn't matter.
So answering your question - Stay with world coordinates.
It also make simple add physics, light calculations, any dimensions ( 1.8 units instead 243 pixels )
I'm not sure if this question is appropriate for this site. I figured this would be the best place to ask. I need to draw 15+ circles on the screen and translate/move each of them per frame. I don't know whether I should use vertices to draw the circle, or simply draw a square and attach an image of a circle on it. I thought it would be more practical/professional to use vertices but I then thought it might be a lot to handle. If each circle had 1000 points(so its smooth), that means each circle has 1002 vertices. 15 of those make 15,030 vertices I'm multiplying by a model matrix per frame. I figured that would be a lot for a device to handle. So then I thought about simply a square with 5 vertices(using a triangle strip) and just attaching a circle image as a texture. This would only make for 75 vertices to update per frame - a lot less. I also would be guaranteed to have a smooth looking circle. I just feel like this way isn't as professional. So I came here hoping for people with experience. Which method should I use for drawing circles? Vertices or Texture mapping? Or another method perhaps? Again, I apologize if this is a dumb question or if it has already been asked.
I currently have an arraylist of points from a freehand drawing on a canvas. I was wondering if there is a simple algorithm to detect if that shape represents a circle.I have already researched this a little and the main items I am pointed at are either the Hough transform or having bitmap images but both of these seem a little over the top for what I need it for. Any pointers to algorithms or implementation would be very helpful.
thanks in advance sansoms,
If I interpret your question correctly, you want to know if all the points are on a circle.
As illustrated in the picture, we pick three points A, B, C from the list and compute the origin O of the presumed circle. By checking the distance between O and each point from the list, we can conclude whether these points are on a circle.
If you do not know what the user wanted to draw (e.g., a circle, an ellipse, a line, or a rectangle), you could use some basic optimization algorithm to find the shape best matching the hand-drawn points.
for each basic shape (oval, rectangle, triangle, line, etc.), create a random instance of that shape and measure the error w.r.t. the given points
optimize each of the shapes (individually) until you have the oval best matching the given points, the rectangle best matching the points, the best triangle, etc.
pick the shape that has the lowest error and draw it
Maybe this answer can give you some ideas: https://stackoverflow.com/a/940041/12860
In short: calculate the second derivative. If it is quite constand, it is probably a circle.
Reading your comment, an easier method to draw a circle is for the user to click the center point, then drag the radius of the circle. It's a lot less calculation, and easier for the user to draw.
You can do the same thing with a rectangle, or any other convex polygon.
For an image editing application i'm trying to draw a gradient around a closed natural cubic spline.
The spline is drawn according to the algorithm and code explained here.
The outcome should look like this (created with GIMP using lots of gaussian blur).
As i could not find any suitable algorithm to determine the distance from the spline, i tought of the following algorithm:
Mark some key points on the spline
Grow or enlarge these points with reference to the center of the closed spline
Create a mesh of triangles between the inner points and the outer points. These
triangles will have the inner vertexes black, and the outer vertexes
white.
As you can see, this solution is quite complex (will probably have to rely on OpenGL) and hence suboptimal.
Can anybody come up with a simpler solution?
Thanks in advance.
It seems you need to build distance transform map outside the spline. Some code for doing it. It is implemented in OpenCV library too.