2

so since I am relatively new to programming I would need a little help with that problem. I am using SimpleCV with Python 2.7 on a Windows Computer. What I am trying to do is to get a (selfwritten) program to tell me the values of the pixels along a preset line, the most important thing here would be the color of each pixel.

I don't really know where to start since I only found examples where it was asked for the values of a single pixel.

What would probably also be important to know is that I don't want to do that with a picture but with a live video made with a webcame and the preset line will be the radius of an object I will track with the webcame.

So to sum it up: I want to track an object with my webcam and need a program to tell me the color (in numbers, so for example "255" for white) of each pixel along he radius line of the tracked object.

This is a prewritten code I am currently using for obejct tracking:

print __doc__

import SimpleCV

display = SimpleCV.Display()
cam = SimpleCV.Camera()
normaldisplay = True

while display.isNotDone():

    if display.mouseRight:
         normaldisplay = not(normaldisplay)
         print "Display Mode:", "Normal" if normaldisplay else "Segmented" 

img = cam.getImage().flipHorizontal()
dist = img.colorDistance(SimpleCV.Color.BLACK).dilate(2)
segmented = dist.stretch(200,255)
blobs = segmented.findBlobs()
if blobs:
    circles = blobs.filter([b.isCircle(0.2) for b in blobs])
    if circles:
        img.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),SimpleCV.Color.BLUE,3)

if normaldisplay:
    img.show()
else:
    segmented.show()

here is a snapshot of the tracked object

I need the pixels color along the radius because I want to know how the light intensity decreases going from the center to the rim.

Does anybody maybe have an idea how to approach this problem? Thank you!

Jennan
  • 89
  • 11

1 Answers1

0

Let's say you have the center (x0, y0). You want to iterate over the pixels on the radius going from (x0, y0) to (x1, y1) which is a point on the circle.

In C++, you would be able to use the LineIterator for that purpose. However, I didn't find it for python...

So you can either implement your own LineIterator in Python (or take the one made by a nice StackOverFlow contributor) or you could resort to a hideous hack if performance is not a critical issue in your application:

  • Create a black binary mask the size of your image
  • Draw your line on this mask
  • Find all non-black pixels using NumPy nonzero function.
  • You've got the pixels of your line (though they are not ordered)
  • Order them according to their distance from the center.

I reckon that just taking the line iterator I linked to on another StackOverflow question is still the easiest way for you.

Community
  • 1
  • 1
Sunreef
  • 4,452
  • 21
  • 33