This repository was archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRCodescanner.py
66 lines (50 loc) · 1.45 KB
/
QRCodescanner.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
65
66
import cv2
from cv2 import QRCodeDetector
cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
from dronekit import *
import time
vehicle = connect('127.0.0.1:14551', baud=921600, wait_ready=True)
#takeoff function
def arm_takeoff(height):
#check if drone is ready
while not vehicle.is_armable:
print("waiting for drone")
time.sleep(1)
#change mode and arm
print("Arming")
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True
#check if drone is armed
while not vehicle.armed:
print("Waiting for arm")
time.sleep(1)
#takeoff
print("Takeoff")
vehicle.simple_takeoff(height)
#report values back every 1s and finally break out
while vehicle.location.global_relative_frame.alt<=(height*0.95):
print("Reached", vehicle.location.global_relative_frame.alt, "m")
time.sleep(0.5)
print("Reached target altitude")
def land():
print("Landing")
vehicle.mode = VehicleMode('RTL')
while vehicle.location.global_relative_frame.alt>=(0.5):
print("Vehilce at",vehicle.location.global_relative_frame.alt,"m")
time.sleep(1)
print("Landed")
while True:
_,image = cap.read()
res,_,_ = detector.detectAndDecode(image)
if res == '1':
arm_takeoff(25)
elif res == '2':
land()
break
cv2.imshow('Video',image)
cv2.waitKey(100)
time.sleep(1)
#close vehicle
vehicle.close()
cv2.destroyAllWindows()