Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using openCV in order to detect a laser beam (point or line). I have managed to get a bw-image showing the laser beam as a white curve. Point2D Class:

class Point2D:
    def __init__(self,x,y):
        self.x = x; self.y = y

    def __add__(self, other):
        return Point2D(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Point2D(self.x - other.x, self.y - other.y)

    def rotate_about_origin(self, angle):
        return Point2D(self.x * cos(angle), self.y * sin(angle))

my detect method (as part of a larger program):

 def detect(self, frame):
        hsv_img = cv2.cvtColor(frame, cv.CV_BGR2HSV)

        # split the video frame into color channels
        h, s, v = cv2.split(hsv_img)
        self.channels['hue'] = h
        self.channels['saturation'] = s
        self.channels['value'] = v

        # Threshold ranges of HSV components; storing the results in place
        self.threshold_image("hue")
        self.threshold_image("saturation")
        self.threshold_image("value")

        # Perform an AND on HSV components to identify the laser!
        self.channels['laser'] = cv2.bitwise_and(
            self.channels['hue'],
            self.channels['value']
        )

        # NOTE: This actually Worked OK for me without using Saturation, but
        # it's something you might want to try.
        #self.channels['laser'] = cv2.bitwise_and(
            #self.channels['saturation'],
            #self.channels['laser']
        #)

        # Merge the HSV components back together.
        hsv_image = cv2.merge([
            self.channels['hue'],
            self.channels['saturation'],
            self.channels['value'],
        ])
        return hsv_image

I have also figured out that by using numpy I can get a matrix of the color representations of the image. Command:

  matrix = numpy.asarray(cv.LoadImageM('Untitled.png', 1)).tolist()

I want also to split my image at n-parts and get the white pixels from each part as points (Point2D)

How can I "fetch" the points of the curve (first finalize it and then get a smoother one) and append them to an array of type Point2D (that I have developed in Python)? By this I mean that I want a "plot" of this curve every n pixels. A better explaination might come from the mathematics background. Suppose that we have the function f(x) = x and we want to get the f(x),f(x+10),f(x+20), .... f(x+10*n) in a point array.

PS I want this to run on my Android Phone

share|improve this question
    
just out of curiosity: how do you plan to run it on android ? –  berak Feb 27 at 14:15
    
I am between running it on a python shell or packaging an apk with buildozer. There is python-targeted development for android such as the sl4a and py4a, as well as kivy (or a combination) –  MaR1oC Feb 27 at 14:18
    
ah, ok. i know sl4a, but i'll have to look into buildozer. thanks for the info ! –  berak Feb 27 at 15:17
    
Ok it is a great tool for application building! –  MaR1oC Feb 28 at 18:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.