LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Anchor a picture on a curve

Hello ,

Using canvas control to load an image , which represent a rail way , but it is a circle not line . Now I want to simulate a train run along with the track , I'd like to know how to do this ? Thanks.

David
0 Kudos
Message 1 of 2
(2,963 Views)
If I understand the problem correctly, you want to be able to trace through a curved line, finding out where each pixel of that line is, and then draw another image (train?) centered around those pixels?

I can think of one fairly simple algorithm that would work and is not expensive. The assumptions it makes are that the line is a single pixel wide, that it is unbroken, and that it is not crossed by another line of the same color.

If that's the case, this is what you can do.

1. Identify the location in pixels of the starting point of the line in the image, and the RGB color of the line.

2. Draw the image containing the line onto the canvas.

In a loop, do the following:

3. use the CanvasGetPixels function to get the color of each of the 8 neighboring
pixels. At each iteration, only two neighboring pixels should match the color of the current pixel, and one of them you should have already visited. The other should be the next pixel in the curve.

4. Use the next pixel in the curve as a center point of where to draw the train (I'm not sure if this is also an image, or some shape, but that shouldn't matter).

5. I guess the line ends when you find no new pixels.

This is probably not the best or most efficient way of doing this, but it should work.

Luis
NI
0 Kudos
Message 2 of 2
(2,963 Views)