-
Notifications
You must be signed in to change notification settings - Fork 1
/
camera.py
47 lines (36 loc) · 1.31 KB
/
camera.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
from __future__ import print_function
from dronekit import connect, VehicleMode, LocationGlobal, LocationGlobalRelative
import time
import math
from pymavlink import mavutil #
import cv2
import argparse
parser = argparse.ArgumentParser(description='Print out vehicle state information. Connects to SITL on local PC by default.')
parser.add_argument('--connect',
help="vehicle connection target string. If not specified, SITL automatically started and used.")
args = parser.parse_args()
connection_string = args.connect
sitl = None
if not connection_string:
import dronekit_sitl
sitl = dronekit_sitl.start_default()
connection_string = sitl.connection_string()
print("\nConnecting to vehicle on: ,s" , connection_string)
vehicle = connect(connection_string, wait_ready=True)
vehicle.wait_ready('autopilot_version')
print("\nGet all vehicle attribute values:")
camera_port = 0
a=0
initial_alt=0.0
final_alt=0.0
while True:
final_alt=float(vehicle.location.global_relative_frame.alt)
if (final_alt-initial_alt)>= 5:
camera = cv2.VideoCapture(camera_port)
camera_capture = camera.read()[1]
file = "image_"+str(a)+".jpg"
cv2.imwrite(file, img=camera_capture)
a=a+1
print("captured at: ",final_alt)
initial_alt=final_alt
del (camera)