Draw gradient along a path in iOS - ios

I've found quite a few sample that archived kind of a similar result, but what I want is to draw a multi-line gradient along an arbitrary path. (I need it to visualize users speed during a run on a MapView)
So the gradient will have quite a few colors and colorLocations.
What I've see so far is one gradient and this one is masked to a path. But that's not what I need.
So the result I want it something like the Nike Runners Club App. They draw a beautiful gradient.
So it should look something like this:

Related

Warping curved rectangle to a regular rectangle

Edit: Upon further research, I've came across similar questions. I guess the process is not as trivial as using the WarpPerspective() function. Here is a similar question and an answer.
I'm using methods like thresholding and canny to extract a rectangular shape from books. Sometimes the rectangles (contours) are deformed like this (pages are not always flat):
As you can see the bottom line is not a straight line. I need to warp it into a rectangle to do further analysis of its inside contents.
Normally, I use WarpPerspective() using the 4 points I get from ApproxPolyDP() with a contour like this and it works fine:
But I can't figure out what to do with a curved rectangle. Here is what I get using the method I use on non-curved rectangles. It's close but not quite what I want:

Fitting a curve to a drawing in Gimp

I'd like to make a logo which contains some mathematically defined shapes (to wit, a log-normal and normal distribution; see below). I can generate an image of these shapes using Python's Matplotlib, but I would like to import this into Gimp.
In Gimp, I'm aware of the tool for drawing Bezier curves by hand, as well as the 'select by color' option which could be used to select the curves. However, I'd like the lines to be a constant thickness. Is there a way to 'fit' two constant-thickness lines to a picture like this in Gimp?
If you have them as Paths (in other words, Bezier curves) just "stroke" them (Edit>Stroke path if done manually, pdb.gimp_edit_stroke_vectors(layer,path) in Python).

Extract coordinates from image file

How to get an array of coordinates of a (drawn) line in image? Coordinates should be relative to image borders. Input: *.img . Output array of coordinates (with fixed step). Any 3rd party software to do this? For example there is high contrast difference - white background and color black line; or red and green etc.
Example:
Oh, you mean non-straight lines. You need to define a "line". Intuitively, you might mean a connected area of the image with a high aspect ratio between the length of its medial axis and the distance between medial axis and edges (ie relatively long and narrow, even if it winds around). Possible approach:
Threshold or select by color. Perhaps select by color based on a histogram of colors, or posterize as described here: Adobe Photoshop-style posterization and OpenCV, then call scipy.ndimage.measurements.label()
For each area above, skeletonize. Helpful tutorial: "Skeletonization using OpenCV-Python". However, you will likely need the distance to the edges as well, so use skimage.morphology.medial_axis(..., return_distance=True)
Do some kind of cleanup/filtering on the skeleton to remove short branches, etc. Thinking about your particular use, and assuming your lines don't loop around, you can just find the longest single path in the skeleton. This is where you can also decide if a shape is a "line" or not, based on how long the longest path in its skeleton is, relative to distance to the edges. Not sure how to best do that in opencv, but "Analyze Skeleton" in Fiji/ImageJ will let you filter by branch length.
What is left is the most elongated medial axis of the original "line" shape. You can resample that to some step that you prefer, or fit it with a spline, etc.
Due to the nature of what you want to do, it is hard to come up with a sample code that will work on a range of images. This is likely to require some careful tuning. I recommend using a small set of images (corpus), running any version of your algo on them and checking the results manually until it is pretty good, then trying it on a large corpus.
EDIT: Original answer, only works for straight lines:
You probably want to use the Hough transform (OpenCV tutorial).
Python sample code: Horizontal Line detection with OpenCV
EDIT: Related question with sample code to skeletonize: How can I get a full medial-axis line with its perpendicular lines crossing it?

Simple OpenCV example to measure Size of Object on a screen

following up on my other question, do you guys know a good example in OpenCV, with a simple Black/White-Calibration Picture and appropriate detection-algorithms?
I just want to show some B&W-image on a screen, take a picture of that image from afar and calculate the size of the shown image, to calculate the distance to said screen.
Before I invent the wheel again, I recon this is so easy that it could be achieved through many different ways in OpenCV, yet I thought I'd ask if there's a preferred way around, possibly with some sample code.
(I got some face-detection code running using haarcascade-xml files already)
PS: I already have the resolution/dpi-part of my screen covered, so I know how big a picture would be in cm on my screen.
EDIT:
I'll make it real simple, I need:
A pattern, that is easily recognizable in an Image. Right now I'm experimenting with a checkerboard. The people who made ARDefender used this.
An appropriate algorithm to tell me the exact pixel coordinates of pattern 1) in a picture using OpenCV.
Well, it's hard to say which image is the best for recognition - in different illumination any color could be interpret as another color. Simple example:
As you can see both traffic signs have red color border but even on one image upper sign border is obviously not red.
So in my opinion you should use image with many different colors (like a rainbow). And also you said that it should be easy recognizable in different angles. That's why circle shape is the best for it.
That's why your image should look like this:
So idea of detection such object is the following:
Make different color segmentation (blue, red, green etc). For this use HSV color space.
Detect circles of specific color on image.
That area which has the biggest count of circles seems to be your object.
you just have to take pictures of your B&W object from several known distances (1m, 2m, 3m, ...) and then for each distance check the size of your object in the corresponding image.
From those datas, you will be able to create a linear function giving you the distance from the size in pixels (y = ax + b should do ;) ), translate it into your code and you're done.
Cheers

iOS - Draw Within an Irregular Area

I'm ok with iOS drawing. I've had no problem drawing circles, lines, etc onto a view. In my latest project I would like to restrict my drawing to an irregular area on my view. Basically I have a paper doll outline (jpg) of a person. I want to be able to draw within that outline but have drawing stop when I reach the border. I'm honestly not really sure what my approach can be to accomplish this. Do I have to do hit testing to see if I'm within this irregular region? I don't think that is realistic if I start with a JPG. Do I need to use a "special" color outside my region and test for that color under my brush? I'm worried that won't be accurate as I'm using a big fat fuzzy brush to draw.
Is it possible to restrict drawing within an irregular boundary?
Of course it's possible!
If you are drawing with CoreGraphics (Quartz), you could use a clipping path, or a bitmap mask.
If you are using CoreAnimation, then try a mask layer.
(It sounds like a bitmap mask is what you want, since you're talking about using an arbitrary JPEG image.)

Resources