I am trying to triangulate some vector data for rendering SVG graphics on to the screen usingopengl, for data that has contors that don't overlap I can triangulate and render these shapes ok but there are cases where contors do overlap and this is where I am having issues.
I currently use a delaunay triangulation algorithm and the data I am using is true type font data. For reference the character I am looking at is (char)260 of the arial font. I enclose a picture from font forge showing the shape.
I can successfully "fill" this shape in using the winding order so I can display this glyph on a bit map image but I don't want to do this here, I'd like to render the glyph using opengl directly (this works fine for the non overlapping glyphs).
Does anyone know of a triangulation algorithm that can cater for overlapping contors or an algorithm that can remove overlaps?
You need a polygon boolean library like this one (open source) to perform a union operation between all character shapes, then to triangulate the outcome.
Related
IOS 11 includes a document scanner and uses the internal class VNDetectRectanglesRequests to find the four corners of a rectangle in an image.
That is the first step for further processing like warping the projected rectangle to get a straight image of the scanned document where all inner angles have 90°.
What is the algorithm used for that computer vision problem? First detect lines using Hough Transform and then detect corners using FAST? What strategy is used to make it fast and robust?
This is more a math question than a programming question beside the fact that I must implement it using Delphi inside a graphic application.
Assuming I have a picture of a sheet of paper. The actual sheet of paper is of course a rectangular area. When the picture is shown on a computer screen the rectangular area is no more rectangular because when the picture was taken, the camera was not perfectly positioned above the sheet of paper. There is all kinds of perspective effects which result in deformations.
My application needs to tweak the image so that the original rectangular area is displayed as a rectangular area on screen.
Most photo processing software have an interactive tool to do that. The user draw a rectangular area on screen around the rectangular object and then drag each corner to deform the displayed rectangular area until he see the real area as rectangular. What I'm looking for is the algorithm to do that computation.
You need to split the problem into 2 steps. Find the edges or corners of the sheet and remap the pixels.
To find the corners or edges it's a really hard problem since they might be invisible, outside of the picture, obstructed, bent or deformed. Assuming you have a very simple setup (black uniform background, white paper, very little distortion) you could run an edge detection kernel over the image then find the 4 outer edges. If you find the edges you can intersect them to find the corners and the other way around.
Once you find the corners run an interpolation over the image to map the pixels onto the rectangle you want. You should be able to get the graphics engine to do this for you if you provide the coordinates of the corners as texture coordinates for the rectangle and map the image as a texture.
I made it sound simple, but you will encounter many parameters to set and experiment with.
It seems (because you mentioned bilinear interpolation) that you need perspective transformations.
There is implementation of perspective transformations (mapping of arbitrary convex quad to rectangle and vice versa) in Anti-Grain Geometry library (exe example). Delphi port.
With agg_trans_perspective one can calculate the matrix of persp. transformation and then apply it to map coordinates from one quad to another.
I used google maps to make a project that records flood incident in a certain area. I used polygons to represent those floods, since the project is for planning purposes it is required of us to output all the historical flood data into a single map. My problem is if I simply just output all polygons, it would look messy and cluttered. So I was wondering what method I could use to represent these polygons in a better fashion. We were advised to use heatmaps, but I can't seem to find tutorials on how to make polygons into heatmaps. Any suggestions would be appreciated. Thanks!
To turn a polygon into a heatmap, render the polygons in black with high transparency into a white bitmap. This should result in a grayscale image, which will be darker where many polygons overlap. Then convert the gray values of the bitmap into the hue value of a corresponding semi-transparent color bitmap.
Why did the rendering look messy? Did you try rendering filled polygons with high transparency and no borderline? That should result in areas that are more prone to flooding being more "highlighted".
What are the standard algorithms used in vector graphics for rendering filled paths?
I'm not only interested in the process of rendering strokes, I also would like to know how the shapes are filled - how it is determined if given point is inside or outside the path (I believe even specifying the rules of what inside and outside mean is not a straightforward thing).
find outline (perimeter as polygon)
this I think you already have
triangulate (or cut to convex polygons)
there are many approaches like:
clip ear
Delaunay
see Wiki Polygon triangulation
fill convex triangles/polygons
this is easy either use
gfx lib like OpenGL,DirectX,...
api like GDI
rasterize on your own like in how to rasterize convex polygons
style
This stuff is more complicated then it sound like at the first hear. For:
outline width pen,stroke
convert outline to polygon by shifting it out or in. For more info see this
outline style pen,stroke
full,dash dot,dot dot,... for more info see this
filling style brush
like hatching which is most complicated from all. It involves heavy polygon tweaking similar but much harder then outline width. Some styles are simpler some extremly complicated for example for equidistant line fill simple loop + intersection + inside polygon test will do. To test polygon inside you can use hit test
I have an image with arbitrary regions shape (say objects), let's assume the background pixels are labeled as zeros whereas any object has a unique label (pixels of object 1 are labeled as 1, object 2 pixels are labeled as 2,...). Now for every object, I need to find the best elliptical fit of its pixels. This requires finding the center of the object, the major and minor axis, and the rotation angle. How can I find these?
Thank you;
Principal Component Analysis (PCA) is one way to go. See Wikipedia here.
The centroid is easy enough to find if your shapes are convex - just a weighted average of intensities over the xy positions - and PCA will give you the major and minor axes, hence the orientation.
Once you have the centre and axes, you have the basis for a set of ellipses that cover your shape. Extending the axes - in proportion - and testing each pixel for in/out, you can find the ellipse that just covers your shape. Or if you prefer, you can project each pixel position onto the major and minor axes and find the rough limits in one pass and then test in/out on "corner" cases.
It may help if you post an example image.
As you seem to be using Matlab, you can simply use the regionprops command, given that you have the Image Processing Toolbox.
It can extract all the information you need (and many more properties of image regions) and it will do the PCA for you, if the PCA-based based approach suits your needs.
Doc is here, look for the 'Centroid', 'Orientation', 'MajorAxisLength' and 'MinorAxisLength' parameters specifically.