Is there any library or algorithm to convert a polygon to a line by shrinking it. I am passing points of my polygon and I want the points of the line as output.
Related
I want to draw a straight line passing through the centroid of the contour, and then there are two intersection coordinates between the straight line and the contour. Finding the distance between the two intersection coordinates. I want to traverse each contour point, draw a straight line passing through the center of mass, make it intersect another point of the contour, and then find the two intersections with the longest distance. I used OpenCV to draw a straight line from the center of mass to the contour, but this is a line segment that does not extend to intersect the contour. Is there any good way to find the intersection of these two longest distances?
The purple line may be the result I want, while the green line is drawn by OpenCV.Please look at the picture:
I have to remove some lines from the sides of hundreds of grayscale images.
In this image lines appear in three sides.
The lines are not consistent though, i.e, they appear above, below, left and/or right side of the image. And they are of unequal length and width.
If you could assume that the borders are free of important information, you may crop the photo like this:
C++ code:
cv::Mat img;
//load your image into img;
int padding=MAX_WIDTH_HEIGHT_OF_THE LINEAS_AREA
img=img(cv::Rect(padding,padding,img.cols-padding,img.rows-padding));
If not, you have to find a less dumb solution like this for example:
Findcontours
Delete contours that are far from the borders.
Draw contours on blank image
Apply hough line with suitable thresholds.
Delete contours that intersect with lines inside the image border.
Another solution, assuming the handwritten shape is connected:
Findcontours
Get the contour with the biggest area.
Draw it on a blank image with -1(fill) flag in the strock argument.
bitwise_and between the original image and the one you made
Another solution, asuming that the handwritten shape could be discontinuity :
Findcontours
Delete any contour that its all points are very close to the border (using euclidian distance with a threshold)
Draw all remaining contours on a blank image with -1(fill) flag in the strock argument.
bitwise_and between the original image and the one you made
P.S. I did not touch HoughLine transform since I do not about the shapes. I assume that some of them may contain very straight lines.
I want to detect small straight lines in a noisy image. For this I
- find contours in an image,
- fit an ellipse on it
- and get the height by width ratio.
- If this ratio exceeds a certain threshold, I declare it as line segment.
This method works fine most of the time. But in certain cases (according to some documentation, when the contours self-intersect), the fitEllipse gives wrong results. It there any other method, I can determine the longevity of the contours? I do not intend to use Hough Lines.
One way to grow a line from contour points is to track pixels on the contour while checking for line straightness. At each new pixel you estimate the longest distance from the covered contour and the line connecting contour's beginning and the current contour point. When this distance exceeds a threshold you stop growing a line. In the picture below, the line is red, contour is black and the distance is green.
In your case (since you aren't growing the line) all you need to do is to connect two contour terminals and then scan the contour to get all the distances to the line and select the largest one. Compare it to your threshold to decide on the linearity of the segment.
Here is how to find the distance from point x, y to the line ax+by+c=0 or to the line defined by two points as in your case: link
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.
Is there any way to draw a line using ID3DXLine with round endings? I am trying to draw a curve from number of line segments, but getting the empty areas where the line segments are connecting.
Performance here is essential.
Thanks!
Any other fast way to draw thick curved line using D3D?
You would be best off using a circular texture (with antialiasing around the edges) and then drawing half the texture at either end of the line. You can then render a strip through the center of the texture the whole way along a rectangle surrounding the line before finishing off with the other half of the texture at the other end. This will give you the effect you are after but its a tad more involved than simply calling "DrawLine" or whatever ...