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