Can an SVG <path> contain both absolute and relative commands? - path

Currently I'm developing an app that converts svg-paths created by Inkscape. Now I'm not clear about the path specification regarding absolute and relative path-combinations. Does the specification say anything about a path definition, that holds relative and absolute coodinates at the same time?
Espacially the case regarding an absolute bezier curve followed by a relative shorthand bezier curve ?
If this case is possible, then I have to compute and keep the current absolute path to make sure I can compute the first controle point of a relative shorthand curve.
Should I ask the question the Inkscape authors ?

Yes mixing absolute and relative path commands is allowed. If you are implementing a tool I'd advise you to read the specification, and the path data section in particular.

yes, it can. using upper and lower case commands like l and L (which means line to) in svg path data works for ex d="M 10,10 L 20,20 l 20,20" (M) moves the pen to (10,10) absolute point then (L) draws a line from (10,10) to (20,20) absolute points and finally (l) draws a line from (20,20) absolute point to (20,20) relative point which is (40,40) absolute point

Related

OpenCV minAreaRect for character deskew

I am implementing a system that needs to deskew characters before recognition. I am currently using OpenCV's minAreaRect to obtain the best rectangle containing the character. I use this rectangle's coordinates to apply warpPerspective transform, so it has to be accurate.
The problem is that for some characters this minAreaRect does not return the best position for the characters, as seen here: http://i.stack.imgur.com/1ibxi.png
Note that the red contours are the minArea rectangle and the green ones the contour itself.
I tried to verify the area of the T box and it appears to be similar to a straight box containing T. Is this the expected behaviour of this function?
Unfortunately this is common behaviour for minAreaRect(). You'll also encounter this problem with the 7 for instance. A common way to solve this is to find the baseline of the characters.
A simple way to do this would be to iterate over your rotatedRect objects and store the angles of the shortest sides and sizes. Then place a rotatedRect of the most common angle and size and replace the outliers with this.

Draw curve with varying line width

I know how to draw curve with Core Graphic or using UIBezierPath.
But, I want to draw a curve that is wide to begin with and thin at the end:
I searched many question about curve, bezier path or something similar on Google. But i can't find any ideal for implementing it.
Can you help me ?
The two methods that immediately come to mind are...
Calculating the path
This is probably the most complex. It would involve calculating the path for the entire shape and adding this as a path and filling it.
Using a line method
You create a series of points that will lie along the centre line of your curve. Maybe 5 points between each point.
Then at each point you can use that as a centre point of a line perpendicular to the tangent of the curve at the point.
The perpendicular line will have a length which you can calculate depending on how far through the curve you are.
Then use this line to create a square path to the line from the previous point.
Then fill that square.
Move to the next point. Add the line and create a box back to the previous line and so on.
At the end are a circle with centre point of the last point. This will create the end.
It's complex but doable if you split down the functions.

How to draw a presentable tree using CFTree?

I have to draw a presentable tree using CFTree. You can see in picture
The should satisfy all principles stated in this link.
The principle are :
Principle 1: The edges of the tree should not cross each other.
Principle 2: All nodes at the same depth should be drawn on the same horizontal line. This helps make clear the structure of the tree.
Principle 3: Trees should be drawn as narrowly as possible.
Principle 4: A parent should be centered over its children.
Principle 5: A subtree should be drawn the same no matter where in the tree it lies.
Principle 6: The child nodes of a parent node should be evenly spaced.
How should I calculate X,Y position of each nodes?
You can solve this problem recursively.
Without diagrams (which would help a lot!) here goes an outline - you need to fill in the details! - of one algorithm for this. The algorithm is being typed directly into the answer - expect errors.
First:
Bounding box a rectangle enclosing the drawing of a (sub)tree.
Anchor as the point that connecting arcs will draw towards (part of the arc may be obscured by the drawing of nodes) to connect to the (sub)tree.
The anchor will be the coordinate origin of the bounding box - so bounding boxes are measurements relative to this point.
A bounding box may have children - bounding boxes for subtrees. The location of each child is relative to the boxes anchor.
Now:
Consider first drawing a single node with no children. Based on your desired size you can determine a bounding box for this single node. You are using circles so the anchor, the (0,0) coordinate origin of the bounding box is at the centre and the bounding box is +/- the radius relative to that. So you have the bounding box's anchor, (0,0), and its size relative to that - say (x minimum, x maximum, y minimum, y maximum) being (-radius, +radius, -radius, +radius). You will probably also wish to store the node's label. So for example for the "L" node in your diagram in total you have a representation (i.e. and object) containing: (0,0), (-radius, +radius, -radius, +radius) & "L".
Now consider drawing a node with a single child. By a recursive call determine the bounding box for the child. Construct a bounding box to enclose the child with your node at the top centre of this box and the child bounding box directly below it. So you have the bounding box's anchor, it's size relative to that, and a single child at an offset from the anchor. So for example for the "H" node above you have: (0,0), (xmin, xmax, ymin, ymax), "H", 1 child at (xoffset, yoffset), child is (a reference to the object) (0,0), (-radius, +radius, -radius, +radius) & "L".
Now consider drawing a node with 2 children, etc.
A single recursive traversal from the root of your tree, at each node combining the information returned from subtrees, produces a structure describing the layout of your tree. Now draw it!
HTH
I realize this is an old thread, but for anyone else who googled CFTREE and found this image and is looking for a similar diagram, I can recommend GraphViz as a solution. I've used it and it's easy and powerful. From ColdFusion or any other language you can call it via the command line, have it create an image, use that image, then delete the image. The reason I mention this software is there a whole science (algothrym) behind how to build a diagram like this. Rather than write it yourself, just use this free software.
To get the data ordered by parent/child, in Oracle you can use the CONNECT BY statement.
Build your string of data then call GraphViz - e.g.,
Then refer to the image
And delete it:

Find Homography for three pairs of 2D/2D correspondents

I have a three feature points in an image and their matches in another image.
My question is how to find a homography that relates these matches to each other?
I know I should solve P3P problem.But I don't know how exactly normalize point sets to this end. After solving P3P how should I get Homography matrix.
Suppose my camera Intrinsic parameters are known.
After that I want to compute 6DOF rigid transform and map every arbitrary points in Image 1 to Image 2.
It's worth mentioning that I don't want to use OpenCV native function like cv::findHomography()
I'd be grateful If you reply clear and complete. Because I followed the instruction from here and here but did not get a correct solution.
I assume you are referring to transformation. If that is the case, see below.
One can find the rotation (R) and (t) from object (target board) to cmaera coordinate system using solvePnP. Based on this idea, R1, t1 and R2, t2 can be found for images 1 and 2 respectively. One can compute the relative transformation (from image 2 to image 1) as follows.
Relative Rotation = inv(R1) * R2
Relative Translation = inv(R1) * (t2 - t1)

Deforming an image so that curved lines become straight lines

I have an image with free-form curved lines (actually lists of small line-segments) overlayed onto it, and I want to generate some kind of image-warp that will deform the image in such a way that these curves are deformed into horizontal straight lines.
I already have the coordinates of all the line-segment points stored separately so they don't have to be extracted from the image. What I'm looking for is an appropriate method of warping the image such that these lines are warped into straight ones.
thanks
You can use methods similar to those developed here:
http://www-ui.is.s.u-tokyo.ac.jp/~takeo/research/rigid/
What you do, is you define an MxN grid of control points which covers your source image.
You then need to determine how to modify each of your control points so that the final image will minimize some energy function (minimum curvature or something of this sort).
The final image is a linear warp determined by your control points (think of it as a 2D mesh whose texture is your source image and whose vertices' positions you're about to modify).
As long as your energy function can be expressed using linear equations, you can globally solve your problem (figuring out where to send each control point) using linear equations solver.
You express each of your source points (those which lie on your curved lines) using bi-linear interpolation weights of their surrounding grid points, then you express your restriction on the target by writing equations for these points.
After solving these linear equations you end up with destination grid points, then you just render your 2D mesh with the new vertices' positions.
You need to start out with a mapping formula that given an output coordinate will provide the corresponding coordinate from the input image. Depending on the distortion you're trying to correct for, this can get exceedingly complex; your question doesn't specify the problem in enough detail. For example, are the curves at the top of the image the same as the curves on the bottom and the same as those in the middle? Do horizontal distances compress based on the angle of the line? Let's assume the simplest case where the horizontal coordinate doesn't need any correction at all, and the vertical simply needs a constant correction based on the horizontal. Here x,y are the coordinates on the input image, x',y' are the coordinates on the output image, and f() is the difference between the drawn line segment and your ideal straight line.
x = x'
y = y' + f(x')
Now you simply go through all the pixels of your output image, calculate the corresponding point in the input image, and copy the pixel. The wrinkle here is that your formula is likely to give you points that lie between input pixels, such as y=4.37. In that case you'll need to interpolate to get an intermediate value from the input; there are many interpolation methods for images and I won't try to get into that here. The simplest would be "nearest neighbor", where you simply round the coordinate to the nearest integer.

Resources