-
Notifications
You must be signed in to change notification settings - Fork 0
/
laseraleatorio.py
64 lines (46 loc) · 2.04 KB
/
laseraleatorio.py
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
import imutils
import time
import cv2
from numpy import linalg as LA
from random import randint
from move_laser import move_laser
from move_laser import convert_to_stepper_coordinates
from math import atan
def random_position(frame_size,step_size):
camera = cv2.VideoCapture(0)
##################comeca lendo o quadro#################################
(grabbed,frame) = camera.read()
if not grabbed:
print("deu ruim na recepcao da imagem")
frame = imutils.resize(frame,width=frame_size)
height, width, channels = frame.shape
current_position_X = width/2 #laser comeca no centro
current_position_Y = height/2 #laser comeca no centro
reached = True
###################inicio do loop de visualizacao + sorteio ##################
while True:
(grabbed,frame) = camera.read()
if not grabbed:
print("deu ruim na recepcao da imagem")
break
frame = imutils.resize(frame,width=frame_size)
if reached == True:
#chegou na posicao desejada, sortear novo alvo
target_position_X = randint(0,width)
target_position_Y = randint(0,height)
reached = False
(reached,current_position_X,current_position_Y) = move_laser(current_position_X,current_position_Y,target_position_X,target_position_Y,step_size)
cv2.circle(frame,(current_position_X ,current_position_Y),2,(0,0,255),2)
cv2.circle(frame,(target_position_X ,target_position_Y),2,(0,255,0),2)
(stepper_X,stepper_Y) = convert_to_stepper_coordinates(current_position_X,current_position_Y,width,height,atan(8.3/20))
#print (stepper_X,stepper_Y)
if (randint(0,100)%20 == 0):
print "objetivo",(target_position_X,target_position_Y)
print "posicao atual",(current_position_X,current_position_Y)
print "angulos stepper" , (stepper_X,stepper_Y)
cv2.imshow("camera", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
camera.release()
cv2.destroyAllWindows()