How can I make DashPathEffect or PathDashPathEffect space dashes consistently - java

You can see in the image that these two dashed lines do not coincide. They are drawn along the same path, starting from the same place with the same DashPathEffect. The only difference is the sweepAngle. I've also tried PathDashPathEffect using a circle as the shape but the result is the same.
I want the dots drawn exactly on top of each other. I can't delete the path underneath, because then at the start of the yellow line, the dots will not align. Is this a bug?

Related

Scrolling background sides appearance of a line

in my game (using libgdx) i use a scrolling background the scrolling Background it's work good for some backgrounds like this :
Good one
but when i draw my own background using inkscape or photoshope if i use a line in the sides of the background or something like shadow the probelm of a black line appear , except if i use a picture with one color and drawing in the middle . that's mean the problem is from the picture but why in the others background it's work good (There is no problem in the code and measurements)???
Appearance of a line
If code would be attached, would be great. But looks like, when drawing sprite, need draw one pixel less at the beginning, or draw one pixel more end in the end of sprite.

Java and OpenCV color detection

I'm working on a project at school, which basically is: writing an application to make a drone fly autonomously, and through scanning QR-codes hung up on walls, be able to navigate through a room in order to complete a certain task.
What I am currently working on, is for the drone to detect cardboard boxes (working as obstacles). These boxes are white, and have a blue circle on them. How I'm planning to solve this, is by scanning the frame for colors and squares:
If the drone detects a square, check if it's white. If it's white, check if it contains a blue circle. If it does, I can say that it most likely is a cardboard box.
This is what the box looks like:
If anyone would be able to provide some pointers as to how I can start working on the color detection, I would be very happy!
PS: I haven't provided any code, since I don't really know what to provide. I would be more than happy to provide some if needed
UPDATE: for anyone stuck at the same problem as I, a fellow student provided an excellent link for my exact situation:
http://opencv-java-tutorials.readthedocs.io/en/latest/08-object-detection.html
I would go from a different angle to do this by detecting the blue circle first.
Detect base colors
see RGB value base color name
Select all blue pixels neighboring white or gray-ish ones
As your circlehas black border then you have to select all blue pixels near white,gray,black... just to be sure. This is the result (Green are selected pixels):
another (more robust) possibility is to select all black pixels neighboring white and blue at the same time.
do a connected components analysis
so merge all connected pixels into polylines
For each polyline decide if it is circle/ellipse/oval
that can be done by investigating angle between line segments. If has sharp spikes then sharp edges are present and it is not an oval. If the circumference is too far from circle/elipse/oval computed from its bounding box then it is not oval but some more complicated curvature.
For each oval decide if it is filled with blue
so just flood fill mask of the oval circumference and compare how many pixels are int the original image blue against those that are not. if the ratio is closer to 100% blue then it is filled blue oval shape....
As your marker has also some features inside you can compute the ratio of all base colors inside it to more accurately detect the marker.
Look at Algorithms: Ellipse matching for some additional ideas.
now you can similarly check if the background is white/gray-ish
There are a lot of other possible approaches like OCR and character similarity or based on FFT/DCT, Hough transform for circles... also you are not bound only to geometric properties comparation instead you can compare histograms...

Determine component overlapped by Line2D

There are no. of components around and on Line2D.I want to find only the overlapped ones.I tried line.getbounds().intersects(component) but it gives the rectangular area components which I don't need.Also,distance sometimes gives me a component which is very near to Line but not on line.Any solution?
Short answer: check if at least one of these two conditions is true
any endpoint of the line is inside the component, use the method contains
the line intersects any side of the component bounds, use the intersect method.
Detailed description:
These are the possible cases:
one endpoint of the line is inside the component (this include the case where the line is entirely inside the component);
the line cross the component but all the end points of the line are outside of the objects;In this case it will intersect two sides, but one is enough to validate.
in all other case, the line and the component do not overlap each other and we do not care.
Only the middle bullet is a bit tricky, however since you are testing only jcomponent, the life is simple, because they are rectangles aligned with the axis. You can easily compute the endpoint of the sides of the bounds of the component. The bounds are given by a point (x,y) the width w and the height h. This gives you the four sides as:
(x,y) - (x+w,y)
(x,y) - (x, y+h)
(x,y+h) - (x, y+h)
(x+w,y) - (x+w,y+h)
If the components you are talking about are java Components then they are rectangular and you can use line.intersects(component.getBounds())
if they are any other kind of shape you have to define that shape and work with the line mathematically if they are not rectangular

Java - split image into jigsaw pieces

I need to create a jigsaw puzzle game. I've already done this in the past using AndEngine, however I've only cut texture into rectangles. Now I need to cut it into proper jigsaw pieces. How can I do that?
Cut the texture into rectangles but for every rectangle take extra space. So you would have a lot of rectangles which overlap each other.
Then you need to have some set of patterns for jigsaw edges (black and white images or you can call it a mask) and generate a mask for every rectangle using those patterns.
The algorithm would be:
create a mask with a size of rectangle and initialise it with white color.
Then choose edge pattens based on rectangle-neighbors if they are initialised or choose edges randomly if neighbors are not yet initialize.
After you chose the patterns, draw them on a mask for every side. So in the end you would have a mask with a shape of a jigsaw piece. white color = visible, black color - transparent.
Then apply the mask to the rectangle when you draw it.
And bare in mind that you don't stack these rectangles based on their actual size, but stack in a way that they would overlay each other...
P.S. I hope you understood what I was trying to say. Sorry, English is not my native language...

Java draw line with border

I'm developing a JApplet in which the user can draw some lines over an image.
Lines can be red or green, but I need to highlight them because I don't know the background color.
So I thought that I can draw a white "border" to the line, and I tried to do this creating other two white lines to the left and to the rigth of the original one. But the result is poor.
Is there a better way to accomplish this goal?
As mentioned by #Jesper, draw the line first using a thicker Stroke (as seen in this answer).
The black outline on the letters has width 2.
g.setStroke(new BasicStroke(2f));

Categories