1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| def f_compute_img_left(self, path, left_limit = 0, right_limit = 320, top_limit = 0, bottom_limit = 240, angle = 0, \
angle_h_vision = 60, angle_v_vision = 36,distance = 410, angle_laser = 76):
img = Image.open(path)
imgx, imgy = img.size
list_xy = []
left_limit = int((imgx * left_limit) / 320)
right_limit = int((imgx * right_limit) / 320)
top_limit = int((imgy * top_limit) / 240)
bottom_limit = int((imgy * bottom_limit) / 240)
for y in range(top_limit, bottom_limit):
for x in range(left_limit, right_limit):
rgb = img.getpixel((x,y))
if rgb == 255:
pixelh = angle_h_vision / imgx
if x >= int(imgx/2):
angle_plus = 180
tetah = (x - int(imgx/2)) * pixelh
else:
angle_plus = 0
tetah = (imgx/2 - x) * pixelh
#d = (L*tan(teta))/(cos60 + sin60 * tan(teta))
d = (distance * math.tan(math.radians(tetah))) / (math.cos(math.radians(angle_laser)) + (math.sin(math.radians(angle_laser)) * math.tan(math.radians(tetah))))
ten_cm = bottom_limit - imgy/2
pixelv = 100/ten_cm
ptx = d * math.cos(math.radians(angle + angle_plus))
pty = d *math.sin(math.radians(angle + angle_plus))
ptz = (imgy - y) * pixelv
list_xy.append((ptx, pty, ptz))
break
return list_xy
#===================================================#
# Init #
#===================================================#
def f_compute_img_right(self, path, left_limit = 0, right_limit = 320, top_limit = 0, bottom_limit = 240, angle = 0, \
angle_h_vision = 60, angle_v_vision = 36,distance = 410, angle_laser = 76):
img = Image.open(path)
imgx, imgy = img.size
list_xy = []
left_limit = int((imgx * left_limit) / 320)
right_limit = int((imgx * right_limit) / 320)
top_limit = int((imgy * top_limit) / 240)
bottom_limit = int((imgy * bottom_limit) / 240)
for y in range(top_limit, bottom_limit):
for x in range(right_limit-1, left_limit,-1):
rgb = img.getpixel((x,y))
if rgb == 255:
pixelh = angle_h_vision / imgx
if x < int(imgx/2):
angle_plus = 180
tetah = (imgx/2 - x) * pixelh
else:
angle_plus = 0
tetah = (x - imgx/2) * pixelh
#d = (L*tan(teta))/(cos60 + sin60 * tan(teta))
d = (distance * math.tan(math.radians(tetah))) / (math.cos(math.radians(angle_laser)) + (math.sin(math.radians(angle_laser)) * math.tan(math.radians(tetah))))
ten_cm = bottom_limit - imgy/2
pixelv = 100/ten_cm
ptx = d * math.cos(math.radians(angle + angle_plus))
pty = d *math.sin(math.radians(angle + angle_plus))
ptz = (imgy - y) * pixelv
list_xy.append((ptx, pty, ptz))
break
return list_xy |
Partager