SlideShare a Scribd company logo
1 of 65
AI 드론 프로그래밍
김 종 현
jhkim3217@gmail.com
2024. 2.
대전대학교 특강
강의 내용
• DJI Tello 드론 기초
• 드론의 종류, 비행원리, Tello 드론 구성요소(HW, SW) 등
• 드론 앱을 사용한 드론 비행 기초 실습
• 드론 비행시 주의 할 점
• Tello SDK를 이용한 파이썬 코딩(1)
• DJITelloPy 모듈
• 기본 동작 제어
• takeoff, land, up/down, forward/backward, cw/ ccw 등
• 키보드 제어
• Tello SDK를 이용한 파이썬 코딩(2)
• OpenCV 기초
• 드론 카메라 이미지 캡쳐 및 저장
• 드론 동영상 전송 및 저장
• 파이썬 기반 AI 드론 코딩
• Cascade Classifier를 이용한 안면 인식
• 드론 제어
• following me 드론 제작
• 팀 프로젝트 : 창의적인 AI 드론 제작
Tello Drone 구성 요소
Tello Drone 구성 요소
Tello 드론 사양
참고 : https://dl-cdn.ryzerobotics.com/downloads/Tello/Tello%20User%20Manual%20v1.4.pdf
프로펠러/ 모터
프로펠러/ 모터
드론의 비행 원리 : Quadcopter
Tello 드론 전용 앱
Tello 드론 전용 앱
• Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
Tello 드론 전용 앱
• Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
Tello 드론 전용 앱
• Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
Tello 드론 전용 앱
• Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
Tello 드론 전용 앱
• Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
실습01 : 드론 앱 사용하기
Tello SDK를 이용한
파이썬 코딩(1)
파이썬 설치
• 파이썬 공식 사이트 : https://www.python.org/
• 파이썬 3.7 ~ 3.8 다운로드
파이참(파이썬 통합개발도구) 설치
• Pycharm Edu 다운로드 및 설치
• https://www.jetbrains.com/ko-kr/pycharm-edu/
파이참 사용하기
• https://blog.dalso.org/language/python/13534
파이썬 기초 프로그래밍
• Python Basics 다운로드
• https://bit.ly/3yiBxxz
Code:
print('Hello World')
myData = 'Hello World'
print(len(myData))
print(type(myData))
Result:
Hello World
11
<class 'str'>
DJITelloPy 모듈
• API : djitellopy.readthedocs.io
• GitHub : https://github.com/damiafuentes/DJITelloPy
• DJITelloPy 모듈 설치
• 터미널
• pip install djitellopy==2.4.0
• 파이참
• [setting]->[Project]->[Python Interpreter] -> + ‘djitellopy 2.4.0’
DJITelloPy 모듈 API :
https://djitellopy.readthedocs.io/en/latest/tello/
기본 동작 제어
• takeoff/ land
• takeoff(), land()
• move up/ down
• move_up(), move_down()
• move left/ right
• move_left(), move_right()
• rotate_cw_ccw
• rotate_clockwise(), rotate_counter_clockwise()
• send_rc_control_async
• send_rc_control(self, left_right_velocity, forward_backward_velocity, up_down_velocity,
yaw_velocity)
실습 01
• takeoff -> landing
from djitellopy import Tello
import time
print("Create Tello object")
tello = Tello()
print("Connect to Tello Drone")
tello.connect()
battery_level = tello.get_battery()
print(f"Battery Life Percentage: {battery_level}")
print("Takeoff!")
tello.takeoff()
print("Sleep for 5 seconds")
time.sleep(5)
print("landing")
tello.land()
print("touchdown.... goodbye")
실습 02
• takeoff -> 3회 up(40) -> down(40) 반복 -> landing
실습 03
• takeoff -> fwd(40) -> fwd(40) -> fwd(40) -> cw(180)
-> fwd(40) -> fwd(40) -> fwd(40) -> land
from djitellopy import Tello
tello = Tello()
tello.connect()
tello.takeoff()
tello.move_left(100)
tello.rotate_clockwise(90)
tello.move_forward(100)
tello.land()
• 참고
반복문 이용하기 : for in range()
from djitellopy import Tello
myTello = Tello()
myTello.connect()
myTello.takeoff()
for i in range (0,3) :
myTello.move_up(30)
myTello.rotate_counter_clockwise(90)
myTello.move_down(30)
myTello.land()
from djitellopy import
Tello
myTello = Tello()
myTello.connect()
myTello.takeoff()
myTello.move_up(30)
myTello.move_down(30)
myTello.move_up(50)
myTello.move_down(50)
myTello.move_up(50)
myTello.move_down(50)
myTello.land()
파이썬 함수 이용하기 : def
from djitellopy import
Tello
myTello = Tello()
myTello.connect()
myTello.takeoff()
myTello.move_up(30)
myTello.move_down(30)
myTello.move_up(30)
myTello.move_down(30)
myTello.move_up(30)
myTello.move_down(30)
myTello.land()
def move_up_down(t):
myTello.move_up(t)
myTello.move_down(t)
for i in range(3):
t = 30
move_up_down(t)
실습 04
• takeoff -> fwd(40) -> fwd(40) -> fwd(40) -> cw(180)
-> fwd(40) -> fwd(40) -> fwd(40) -> cw(180) -> land
• fwd(40)을 반복문으로 구현해 보자
input() 함수를 사용한 드론 제어
from djitellopy import tello
myTello = tello.Tello()
myTello.connect()
battery_level = tello.get_battery()
print(battery_level)
while True:
command = int(input("Enter Command!"))
print(command, end="n")
if (command == 1):
myTello.takeoff()
elif (command == 2):
myTello.move_up(30)
elif (command == 3):
myTello.move_down(30)
elif (command == 4):
myTello.land()
else:
break
print("Drone mission completed!")
실습 05 : input() 함수를 이용한 드론 조정기 만들기
1. Takeoff()
2. move_up(20)
3. move_down(20)
4. move_left(20)
5. move_right(20)
6. move_forward(20)
7. move_backward(20)
8. rotate_clockwise(90)
9. rotate_counter_clockwose(90)
10. flip_back()
11. flip_forward()
12. flip_left()
13. flip_right()
14. land()
실습 06 : cross flight 미션
실습 06 : cross flight 미션
from djitellopy import Tello
import time
print("Create Tello object")
tello = Tello()
print("Connect to Tello Drone")
tello.connect()
battery_level = tello.get_batte
ry()
print(battery_level)
print("Takeoff!")
tello.takeoff()
time.sleep(1)
travel_distance_cm = 50
#tello.go_xyz_speed(x,y,z, speed)
# x - (+)foward/(-)backwards
# y - (+)left/(-)right
# z - (+)up/(-)down
tello.go_xyz_speed(0, 0, travel_distance_cm, 20)
print("sleep")
time.sleep(0.5)
tello.go_xyz_speed(0, travel_distance_cm, -travel_distanc
e_cm, 20)
print("sleep")
time.sleep(0.5)
tello.go_xyz_speed(0, 0, travel_distance_cm, 20)
print("sleep")
time.sleep(0.5)
# x - (+)foward/(-)backwards
# y - (+)left/(-)right
# z - (+)up/(-)down
tello.go_xyz_speed(0, -travel_distance_cm, -travel_distan
ce_cm, 20)
print("sleep")
time.sleep(0.5)
print("landing")
Opencv를 이용한
드론의 이미지, 동영상 처리
https://opencv.org/
드론 사진 촬영, 저장하기
import cv2
from djitellopy import Tello
tello = Tello()
tello.connect()
tello.streamon()
frame_read = tello.get_frame_read()
tello.takeoff()
cv2.imwrite("picture.png", frame_read.frame)
tello.land()
드론 비디오 촬영, 전송
from djitellopy import tello
import cv2
import time
tello = tello.Tello()
tello.connect()
battery_level = tello.get_battery()
print(f"Battery Life Percentage: {battery_level}")
time.sleep(2)
print("Turn Video Stream On")
tello.streamon()
# read a single image from the Tello video feed
print("Read Tello Image")
frame_read = tello.get_frame_read()
print(type(frame_read))
time.sleep(2)
while True:
# read a single image from the Tello video feed
print("Read Tello Image")
tello_video_image = frame_read.frame
# use opencv to write image
if tello_video_image is not None:
cv2.imshow("TelloVideo", tello_video_image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
tello.streamoff()
cv2.destroyWindow('TelloVideo')
cv2.destroyAllWindows()
드론 키보드 제어하기
• manual-control-opencv
from djitellopy import Tello
import cv2, math, time
tello = Tello()
tello.connect()
tello.streamon()
frame_read = tello.get_frame_read()
while True:
img = frame_read.frame
cv2.imshow("drone", img)
key = cv2.waitKey(1) & 0xff
if key == 27: # ESC
break
elif key == ord('t'):
tello.takeoff()
elif key == ord('w'):
tello.move_forward(30)
elif key == ord('s'):
tello.move_back(30)
elif key == ord('a'):
tello.move_left(30)
elif key == ord('d'):
tello.move_right(30)
elif key == ord('e'):
tello.rotate_clockwise(30)
elif key == ord('q'):
tello.rotate_counter_clockwise(30)
elif key == ord('r'):
tello.move_up(30)
elif key == ord('f'):
tello.move_down(30)
tello.land()
cv2.destroyAllWindows()
실습 04
• ‘드론 키보드 제어하기’를 드론 카메라 대신, PC 웹캠을 사용하
여 PC에서 비디오 스트림을 보여 주도록 만드시오
• cv2.VideoCapture(0)
• ret, frame = cap.read()
• cv2.imshow(“Video”, frame)
• https://github.com/DIT-AI-Drone-
Course/SOURCE/blob/main/take_picture_opencv.py
Tello SDK를 이용한
파이썬 코딩(2)
Opencv 기초
• https://opencv.org/
• % pip install opencv-python 혹은 파이참 add(+) opencv-python
파이썬 Opencv 모듈 설치
• 파이참
• 설정 -> 프로젝트 -> Python 인터프리터 -> + -> opencv-python
드론 사진 촬영, 저장하기
import cv2
from djitellopy import Tello
battery_level = tello.get_battery()
print(battery_level)
tello = Tello()
tello.connect()
tello.streamon()
frame_read = tello.get_frame_read()
tello.takeoff()
cv2.imwrite("picture.png",
frame_read.frame)
tello.land()
Opencv로 드론 비디오 읽기, 보기
from djitellopy import tello
import cv2
import time
tello = tello.Tello()
tello.connect()
battery_level = tello.get_battery()
print(battery_level)
print("Turn Video Stream On")
tello.streamon()
time.sleep(2)
while True:
# read a single image from the Tello video feed
frame_read = tello.get_frame_read()
tello_video_image = frame_read.frame
# 이미지 크기 조정 “ resize()
image = cv2.resize(tello_video_image, (360, 240))
# use opencv to write image
if image is not None:
cv2.imshow("TelloVideo", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
tello.streamoff()
cv2.destroyWindow('TelloVideo')
cv2.destroyAllWindows()
드론 비디오 촬영, 전송 : Opencv 키보드 제어
from djitellopy import tello
import cv2
import time
tello = tello.Tello()
tello.connect()
battery_level =
tello.get_battery()
print(battery_level)
time.sleep(2)
tello.streamon()
frame_read =
tello.get_frame_read()
while True:
frame = frame_read.frame
frame = cv2.resize(frame, (360*2, 240*2)) # 이미지 크기
조정
while True:
frame = frame_read.frame
if frame is not None:
cv2.imshow("TelloVideo", frame)
k = cv2.waitKey(5) & 0xFF
if k == ord('q'):
break
elif k == ord('t'):
tello.takeoff()
elif k == ord('u'):
tello.move_up(50)
elif k == ord('c'):
tello.rotate_clockwise(360)
elif k == ord('l'):
tello.land()
else :
print(‘no key!!!’)
tello.streamoff()
cv2.destroyWindow('TelloVideo')
cv2.destroyAllWindows()
Opencv로 드론 키보드 제어하기
• manual-control-opencv
from djitellopy import Tello
import cv2, time
tello = Tello()
tello.connect()
battery_level = tello.get_battery()
print(battery_level)
tello.streamon()
frame_read = tello.get_frame_read()
frame = cv2.resize(frame, (360*2, 240*2))
while True:
img = frame_read.frame
cv2.imshow("drone", img)
key = cv2.waitKey(1) & 0xff
if key == ord(‘q’):
break
elif key == ord('t'):
tello.takeoff()
elif key == ord(‘f'):
tello.move_forward(30)
elif key == ord(‘b'):
tello.move_back(30)
elif key == ord(‘l'):
tello.move_left(30)
elif key == ord(‘r'):
tello.move_right(30)
elif key == ord(‘c'):
tello.rotate_clockwise(30)
elif key == ord(‘r'):
tello.rotate_counter_clockwise(30)
elif key == ord(‘u'):
tello.move_up(30)
elif key == ord(‘d'):
tello.move_down(30)
tello.streamoff()
cv2.destroyWindow(‘drone')
cv2.destroyAllWindows()
• 소스 코드 :
https://github.com/damiafuentes/DJITelloPy/
blob/master/examples/manual-control-opencv.py
드론이 촬영/저장 하면서 동시에 비행하기 : 쓰레드(Thread)
import time, cv2
from threading import Thread
from djitellopy import Tello
tello = Tello()
tello.connect()
battery_level = tello.get_battery()
print(battery_level)
keepRecording = True
tello.streamon()
frame_read = tello.get_frame_read()
def videoRecorder():
height, width, _ = frame_read.frame.shape
# create a VideoWrite object, recoring to ./video.avi
video = cv2.VideoWriter('video3.avi', cv2.VideoWriter_fourcc(*'XVID'), 30, (width, height))
while keepRecording:
tello_video_image = frame_read.frame
tello_video_image = cv2.resize(tello_video_image, (360 * 2, 240 * 2))
# PC에 Tello 촬영 동영상 저장
video.write(frame_read.frame)
if tello_video_image is not None:
cv2.imshow('video', tello_video_image)
time.sleep(1 / 30)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyWindow('video')
cv2.destroyAllWindows()
# we need to run the recorder in a seperate thread
recorder = Thread(target=videoRecorder)
recorder.start()
tello.takeoff()
tello.move_up(30)
tello.rotate_counter_clockwise(360)
tello.land()
keepRecording = False
recorder.join()
• 소스 코드 다운로드 : https://drive.google.com/file/d/1jZD-DjCZK8cVg1r-20hhr4-RcYzW9-5-/view?usp=sharing
파이썬 기반 AI 드론 코딩
Opencv Face Detection
• pre-training model 다운로드
• https://github.com/opencv/opencv/blob/master/data/haarcascades
얼굴 인식하기 : Cascade Classifier
얼굴 인식하기 : Cascade Classifier
import cv2
from djitellopy import tello
tello = tello.Tello()
tello.connect()
battery_level = tello.get_battery()
print(battery_level)
tello.streamon()
while True:
img = tello.get_frame_read().frame
img = cv2.resize(img, (360*2, 240*2))
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.imshow('frame',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
tello.streamoff()
cv2.destroyAllWindows()
얼굴 인식하기 : Cascade Classifier
import cv2
from djitellopy import tello
tello = tello.Tello()
tello.connect()
battery_level = tello.get_battery()
print(battery_level)
tello.streamon()
while True:
img = tello.get_frame_read().frame
img = cv2.resize(img, (360, 240))
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray, 1.2, 8)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
cx = x + w // 2
cy = y + h // 2
area = w * h
cv2.circle(img, (cx, cy), 5, (0, 255, 0), cv2.FILLED)
print('area =', area)
cv2.imshow('frame',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
* 소스 코드 : https://drive.google.com/file/d/1jZLuuovY-tWJdwy1LYD4knpCQkvAjzxk/view?usp=sharing
* haarcascade_frontalface_default.xml 파일 : https://drive.google.com/file/d/1j_Hjo0N6v0HtL1F55ekFBbQ6yxKT3SrQ/view?usp=sharing
얼굴 추적 드론의 원리를 생각해 봅시다
Face Tracking 드론 제어
• back, forward
• ccw, cw
• up, down
인식된 얼굴 중심점(cx, cy)과 전체 프레임 중심점(tcx, tcy) 차이
import cv2
from djitellopy import tello
tello = tello.Tello()
tello.connect()
battery_level = tello.get_battery()
print(battery_level)
tello.streamon()
while True:
img = tello.get_frame_read().frame
img = cv2.resize(img, (360*2, 240*2))
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray, 1.3, 5)
if len(faces) == 1:
print("face found")
print('faces', faces)
else:
print("face not found")
# 전체 화면의 중심점(center)
tcx = 360
tcy = 240
cv2.circle(img, (tcx, tcy), 10, (255, 0, 0), cv2.FILLED)
# 인식된 얼굴 사각형 박스 그리기
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
cx = x + w // 2
cy = y + h // 2
area = w * h
cv2.circle(img, (cx, cy), 10, (0, 255, 0), cv2.FILLED)
print('area =', area)
# 전체 이미지 중심과 얼굴 이지미 중심 간의 선 그리기기
cv2.line(img, (cx, cy), (tcx, tcy), (255, 0, 0), 2)
cv2.imshow('frame',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
tello.streamoff()
cv2.destroyAllWindows()
forward/ backward 제어
# 얼굴 이미지 크기 : z_area = offset_z
offset_z = w * h
# 얼굴 이미지 크기 update 및 forward/ backward 제어
def adjust_tello_position(offsetz):
f not 15000 <= offset_z <= 30000 and offset_z != 0:
if offset_z < 15000:
tello.move_forward(20)
elif offset_z > 30000:
tello.move_back(20)
실습 소스 : https://drive.google.com/file/d/1fJn9bOhB9cEKs71fDCtqzvWxQfNcb4z5/view?usp=sharing
left/ right 제어
offset_x = face_center_x - center_x
def adjust_tello_position(offset_x):
"""
Adjusts the position of the tello drone based on the offset values given from th
e frame
:param offset_x: Offset between center and face x coordinates
"""
if not -90 <= offset_x <= 90 and offset_x != 0:
# offset_x가 음수이면 시계 반대 방향으로 일정 거리 만큼 이동
if offset_x < 0:
tello.rotate_counter_clockwise(10)
# offset_x가 양수이면 시계 방향으로 일정 거리 만큼 이동
elif offset_x > 0:
tello.rotate_clockwise(10)
실습 소스 : https://drive.google.com/file/d/1WXTTag3aDv66SXSCYzapRxOcCA3PNnSK/view?usp=sharing
up/ down 제어
# Add 30 so that the drone covers as much of the subject as possible
offset_y = face_center_y - center_y - 30
"""
Adjusts the position of the tello drone based on the offset values given
from the frame
:param offset_y: Offset between center and face y coordinates
"""
if not -70 <= offset_y <= 70 and offset_y != -30:
if offset_y < 0:
print('move up')
tello.move_up(20)
elif offset_y > 0:
print('move down')
tello.move_down(20)
실습 소스 : https://drive.google.com/file/d/1WXTTag3aDv66SXSCYzapRxOcCA3PNnSK/view?usp=sharing
Face following 제어
소스 코드 : https://drive.google.com/file/d/1f4Xcq8W4HL7tRSILb-hXrV9Jd-gywPPp/view?usp=sharing
Face Detection AI 알고리즘
• Haar Cascade
• https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcas
cade_frontalface_default.xml
• Dlib : HOG + CNN
• https://github.com/davisking/dlib
• MTCNN
• https://github.com/ipazc/mtcnn
• OpenCV DNN : Caffe based DNN
• https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector
• YOLO
• https://velog.io/@hhhong/Object-Detection-with-YOLO
AI 드론 프로젝트
• PID 제어
• https://github.com/ivmech/ivPID
• Custom 훈련 데이터
• 전이학습(fine tuning)
• PoseNet
• 제스쳐 인식 제어
• Dlib
• facial landmark 탐지
• YOLO
• 실시간 객체 탐지
손 제스쳐 기반 드론 제어
• MediaPipe
• https://google.github.io/mediapipe/
참고 자료
• https://www.youtube.com/watch?v=LmEcyQnfpDA&t=3576s
• https://github.com/juanmapf97/Tello-Face-Recognition
• https://google.github.io/mediapipe/
• https://www.droneblocks.io/

More Related Content

Similar to 파이썬 AI 드론 프로그래밍

Processing+Open Cv
Processing+Open CvProcessing+Open Cv
Processing+Open CvChrissung
 
코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우Arawn Park
 
I phone 2 release
I phone 2 releaseI phone 2 release
I phone 2 releaseJaehyeuk Oh
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...Seok-joon Yun
 
11장 윈도우 스레드 풀
11장 윈도우 스레드 풀11장 윈도우 스레드 풀
11장 윈도우 스레드 풀홍준 김
 
11장 윈도우 스레드 풀 + 12장 파이버
11장 윈도우 스레드 풀 + 12장 파이버11장 윈도우 스레드 풀 + 12장 파이버
11장 윈도우 스레드 풀 + 12장 파이버홍준 김
 
[1B4]안드로이드 동시성_프로그래밍
[1B4]안드로이드 동시성_프로그래밍[1B4]안드로이드 동시성_프로그래밍
[1B4]안드로이드 동시성_프로그래밍NAVER D2
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?NAVER D2
 
Web Components 101 polymer & brick
Web Components 101 polymer & brickWeb Components 101 polymer & brick
Web Components 101 polymer & brickyongwoo Jeon
 
배워봅시다 머신러닝 with TensorFlow
배워봅시다 머신러닝 with TensorFlow배워봅시다 머신러닝 with TensorFlow
배워봅시다 머신러닝 with TensorFlowJang Hoon
 
[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기
[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기
[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기SuJang Yang
 
[드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23][드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23]chcbaram
 
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기Jaeseung Ha
 
[Google I_O Extended Daejeon 2023] 처음 시작하는 Flutter
[Google I_O Extended Daejeon 2023] 처음 시작하는  Flutter[Google I_O Extended Daejeon 2023] 처음 시작하는  Flutter
[Google I_O Extended Daejeon 2023] 처음 시작하는 FlutterSuJang Yang
 
Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기성일 한
 
사물인터넷 노트7_사물인터넷과 영상처리
사물인터넷 노트7_사물인터넷과 영상처리사물인터넷 노트7_사물인터넷과 영상처리
사물인터넷 노트7_사물인터넷과 영상처리Dong Hwa Jeong
 
유니티로 flappy brid 만들기(Unity 5.1)
유니티로 flappy brid 만들기(Unity 5.1)유니티로 flappy brid 만들기(Unity 5.1)
유니티로 flappy brid 만들기(Unity 5.1)Changwon National University
 
[WEB UI BASIC] WEB Animation 1탄
[WEB UI BASIC] WEB Animation 1탄[WEB UI BASIC] WEB Animation 1탄
[WEB UI BASIC] WEB Animation 1탄Jae Woo Woo
 
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍흥배 최
 

Similar to 파이썬 AI 드론 프로그래밍 (20)

Processing+Open Cv
Processing+Open CvProcessing+Open Cv
Processing+Open Cv
 
코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우코틀린 멀티플랫폼, 미지와의 조우
코틀린 멀티플랫폼, 미지와의 조우
 
I phone 2 release
I phone 2 releaseI phone 2 release
I phone 2 release
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
 
11장 윈도우 스레드 풀
11장 윈도우 스레드 풀11장 윈도우 스레드 풀
11장 윈도우 스레드 풀
 
11장 윈도우 스레드 풀 + 12장 파이버
11장 윈도우 스레드 풀 + 12장 파이버11장 윈도우 스레드 풀 + 12장 파이버
11장 윈도우 스레드 풀 + 12장 파이버
 
[1B4]안드로이드 동시성_프로그래밍
[1B4]안드로이드 동시성_프로그래밍[1B4]안드로이드 동시성_프로그래밍
[1B4]안드로이드 동시성_프로그래밍
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
 
Web Components 101 polymer & brick
Web Components 101 polymer & brickWeb Components 101 polymer & brick
Web Components 101 polymer & brick
 
배워봅시다 머신러닝 with TensorFlow
배워봅시다 머신러닝 with TensorFlow배워봅시다 머신러닝 with TensorFlow
배워봅시다 머신러닝 with TensorFlow
 
[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기
[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기
[Flutter Meetup In Songdo] 상태관리 올바르게 쓰기
 
[드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23][드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23]
 
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
NDC 2017 하재승 NEXON ZERO (넥슨 제로) 점검없이 실시간으로 코드 수정 및 게임 정보 수집하기
 
[Google I_O Extended Daejeon 2023] 처음 시작하는 Flutter
[Google I_O Extended Daejeon 2023] 처음 시작하는  Flutter[Google I_O Extended Daejeon 2023] 처음 시작하는  Flutter
[Google I_O Extended Daejeon 2023] 처음 시작하는 Flutter
 
Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기Python 으로 Slackbot 개발하기
Python 으로 Slackbot 개발하기
 
사물인터넷 노트7_사물인터넷과 영상처리
사물인터넷 노트7_사물인터넷과 영상처리사물인터넷 노트7_사물인터넷과 영상처리
사물인터넷 노트7_사물인터넷과 영상처리
 
유니티로 flappy brid 만들기(Unity 5.1)
유니티로 flappy brid 만들기(Unity 5.1)유니티로 flappy brid 만들기(Unity 5.1)
유니티로 flappy brid 만들기(Unity 5.1)
 
[WEB UI BASIC] WEB Animation 1탄
[WEB UI BASIC] WEB Animation 1탄[WEB UI BASIC] WEB Animation 1탄
[WEB UI BASIC] WEB Animation 1탄
 
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
 
I os 1
I os 1I os 1
I os 1
 

More from Jong-Hyun Kim

Google Teachable machine을 이용한 AI 서비스 만들기
Google Teachable machine을 이용한  AI 서비스 만들기Google Teachable machine을 이용한  AI 서비스 만들기
Google Teachable machine을 이용한 AI 서비스 만들기Jong-Hyun Kim
 
모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육
모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육
모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육Jong-Hyun Kim
 
고등직업교육에서의 AI 교육 사례 및 방향
고등직업교육에서의 AI 교육 사례 및 방향고등직업교육에서의 AI 교육 사례 및 방향
고등직업교육에서의 AI 교육 사례 및 방향Jong-Hyun Kim
 
Edge AI 및 학생 프로젝트 소개
Edge AI 및 학생 프로젝트 소개Edge AI 및 학생 프로젝트 소개
Edge AI 및 학생 프로젝트 소개Jong-Hyun Kim
 
초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례
초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례
초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례Jong-Hyun Kim
 
Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼
Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼 Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼
Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼 Jong-Hyun Kim
 
IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019Jong-Hyun Kim
 
부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발
부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발 부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발
부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발 Jong-Hyun Kim
 
micro:bit 프로그래밍 기초
micro:bit 프로그래밍 기초 micro:bit 프로그래밍 기초
micro:bit 프로그래밍 기초 Jong-Hyun Kim
 
프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템
프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템
프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템Jong-Hyun Kim
 
딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러
딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러
딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러Jong-Hyun Kim
 
모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석
모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석
모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석Jong-Hyun Kim
 
딥러닝을 이용한 지능형 IoT 스마트 홈 미러
딥러닝을 이용한 지능형 IoT 스마트 홈 미러딥러닝을 이용한 지능형 IoT 스마트 홈 미러
딥러닝을 이용한 지능형 IoT 스마트 홈 미러Jong-Hyun Kim
 
클라우드 기반 지능형 IoT 공기청정기
클라우드 기반 지능형 IoT 공기청정기클라우드 기반 지능형 IoT 공기청정기
클라우드 기반 지능형 IoT 공기청정기Jong-Hyun Kim
 
스마트 공기 톡톡
스마트 공기 톡톡스마트 공기 톡톡
스마트 공기 톡톡Jong-Hyun Kim
 
데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용
데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용
데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용Jong-Hyun Kim
 
모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합 SW 교육 사례
모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합  SW 교육 사례모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합  SW 교육 사례
모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합 SW 교육 사례Jong-Hyun Kim
 
동의대학교 산업융합시스템학부 특강
동의대학교 산업융합시스템학부 특강동의대학교 산업융합시스템학부 특강
동의대학교 산업융합시스템학부 특강Jong-Hyun Kim
 
부산 알로이시오 초등학교 창의융합 SW 교육 사례
부산 알로이시오 초등학교 창의융합 SW 교육 사례부산 알로이시오 초등학교 창의융합 SW 교육 사례
부산 알로이시오 초등학교 창의융합 SW 교육 사례Jong-Hyun Kim
 
데이터를 통한 시민과의 소통
데이터를 통한 시민과의 소통데이터를 통한 시민과의 소통
데이터를 통한 시민과의 소통Jong-Hyun Kim
 

More from Jong-Hyun Kim (20)

Google Teachable machine을 이용한 AI 서비스 만들기
Google Teachable machine을 이용한  AI 서비스 만들기Google Teachable machine을 이용한  AI 서비스 만들기
Google Teachable machine을 이용한 AI 서비스 만들기
 
모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육
모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육
모두의 AI 교육 : 산 ⦁ 학 ⦁ 관 협력으로 모색해 보는 부산 AI 교육
 
고등직업교육에서의 AI 교육 사례 및 방향
고등직업교육에서의 AI 교육 사례 및 방향고등직업교육에서의 AI 교육 사례 및 방향
고등직업교육에서의 AI 교육 사례 및 방향
 
Edge AI 및 학생 프로젝트 소개
Edge AI 및 학생 프로젝트 소개Edge AI 및 학생 프로젝트 소개
Edge AI 및 학생 프로젝트 소개
 
초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례
초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례
초보 유투버의 IT과목 실시간 온.오프라인 융합 강의 사례
 
Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼
Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼 Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼
Busan Citizen Censor : 부산 시민 참여 스마트시티 오픈데이터 플랫폼
 
IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019
 
부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발
부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발 부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발
부산 전기차(EV) 충전소 네비게이션 모바일 앱 개발
 
micro:bit 프로그래밍 기초
micro:bit 프로그래밍 기초 micro:bit 프로그래밍 기초
micro:bit 프로그래밍 기초
 
프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템
프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템
프로브 차량(Porbe Vehicle)을 이용한 IoT 기반 실시간 환경 모니터링 시스템
 
딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러
딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러
딥러닝을 이용한 컬러 테라피 메디컬 IoT 스마트 미러
 
모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석
모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석
모션 인식을 이용한 스마트 안전 헬맷 개발 및 자전거 사고 빅데이터 분석
 
딥러닝을 이용한 지능형 IoT 스마트 홈 미러
딥러닝을 이용한 지능형 IoT 스마트 홈 미러딥러닝을 이용한 지능형 IoT 스마트 홈 미러
딥러닝을 이용한 지능형 IoT 스마트 홈 미러
 
클라우드 기반 지능형 IoT 공기청정기
클라우드 기반 지능형 IoT 공기청정기클라우드 기반 지능형 IoT 공기청정기
클라우드 기반 지능형 IoT 공기청정기
 
스마트 공기 톡톡
스마트 공기 톡톡스마트 공기 톡톡
스마트 공기 톡톡
 
데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용
데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용
데이터를 통한 지역 시민과의 소통 : 데이터의 공개와 활용
 
모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합 SW 교육 사례
모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합  SW 교육 사례모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합  SW 교육 사례
모두를 위한 소프트웨어 교육 : 초등학교의 프로젝트 기반 창의융합 SW 교육 사례
 
동의대학교 산업융합시스템학부 특강
동의대학교 산업융합시스템학부 특강동의대학교 산업융합시스템학부 특강
동의대학교 산업융합시스템학부 특강
 
부산 알로이시오 초등학교 창의융합 SW 교육 사례
부산 알로이시오 초등학교 창의융합 SW 교육 사례부산 알로이시오 초등학교 창의융합 SW 교육 사례
부산 알로이시오 초등학교 창의융합 SW 교육 사례
 
데이터를 통한 시민과의 소통
데이터를 통한 시민과의 소통데이터를 통한 시민과의 소통
데이터를 통한 시민과의 소통
 

파이썬 AI 드론 프로그래밍

  • 1. AI 드론 프로그래밍 김 종 현 jhkim3217@gmail.com 2024. 2. 대전대학교 특강
  • 2. 강의 내용 • DJI Tello 드론 기초 • 드론의 종류, 비행원리, Tello 드론 구성요소(HW, SW) 등 • 드론 앱을 사용한 드론 비행 기초 실습 • 드론 비행시 주의 할 점 • Tello SDK를 이용한 파이썬 코딩(1) • DJITelloPy 모듈 • 기본 동작 제어 • takeoff, land, up/down, forward/backward, cw/ ccw 등 • 키보드 제어 • Tello SDK를 이용한 파이썬 코딩(2) • OpenCV 기초 • 드론 카메라 이미지 캡쳐 및 저장 • 드론 동영상 전송 및 저장 • 파이썬 기반 AI 드론 코딩 • Cascade Classifier를 이용한 안면 인식 • 드론 제어 • following me 드론 제작 • 팀 프로젝트 : 창의적인 AI 드론 제작
  • 5. Tello 드론 사양 참고 : https://dl-cdn.ryzerobotics.com/downloads/Tello/Tello%20User%20Manual%20v1.4.pdf
  • 8. 드론의 비행 원리 : Quadcopter
  • 10. Tello 드론 전용 앱 • Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
  • 11. Tello 드론 전용 앱 • Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
  • 12. Tello 드론 전용 앱 • Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
  • 13. Tello 드론 전용 앱 • Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
  • 14. Tello 드론 전용 앱 • Tello 사용자 매뉴얼 : https://bit.ly/3ygby6T
  • 15. 실습01 : 드론 앱 사용하기
  • 17. 파이썬 설치 • 파이썬 공식 사이트 : https://www.python.org/ • 파이썬 3.7 ~ 3.8 다운로드
  • 18. 파이참(파이썬 통합개발도구) 설치 • Pycharm Edu 다운로드 및 설치 • https://www.jetbrains.com/ko-kr/pycharm-edu/
  • 20. 파이썬 기초 프로그래밍 • Python Basics 다운로드 • https://bit.ly/3yiBxxz Code: print('Hello World') myData = 'Hello World' print(len(myData)) print(type(myData)) Result: Hello World 11 <class 'str'>
  • 21. DJITelloPy 모듈 • API : djitellopy.readthedocs.io • GitHub : https://github.com/damiafuentes/DJITelloPy • DJITelloPy 모듈 설치 • 터미널 • pip install djitellopy==2.4.0 • 파이참 • [setting]->[Project]->[Python Interpreter] -> + ‘djitellopy 2.4.0’
  • 22. DJITelloPy 모듈 API : https://djitellopy.readthedocs.io/en/latest/tello/
  • 23. 기본 동작 제어 • takeoff/ land • takeoff(), land() • move up/ down • move_up(), move_down() • move left/ right • move_left(), move_right() • rotate_cw_ccw • rotate_clockwise(), rotate_counter_clockwise() • send_rc_control_async • send_rc_control(self, left_right_velocity, forward_backward_velocity, up_down_velocity, yaw_velocity)
  • 24. 실습 01 • takeoff -> landing
  • 25. from djitellopy import Tello import time print("Create Tello object") tello = Tello() print("Connect to Tello Drone") tello.connect() battery_level = tello.get_battery() print(f"Battery Life Percentage: {battery_level}") print("Takeoff!") tello.takeoff() print("Sleep for 5 seconds") time.sleep(5) print("landing") tello.land() print("touchdown.... goodbye")
  • 26. 실습 02 • takeoff -> 3회 up(40) -> down(40) 반복 -> landing
  • 27. 실습 03 • takeoff -> fwd(40) -> fwd(40) -> fwd(40) -> cw(180) -> fwd(40) -> fwd(40) -> fwd(40) -> land
  • 28. from djitellopy import Tello tello = Tello() tello.connect() tello.takeoff() tello.move_left(100) tello.rotate_clockwise(90) tello.move_forward(100) tello.land() • 참고
  • 29. 반복문 이용하기 : for in range() from djitellopy import Tello myTello = Tello() myTello.connect() myTello.takeoff() for i in range (0,3) : myTello.move_up(30) myTello.rotate_counter_clockwise(90) myTello.move_down(30) myTello.land() from djitellopy import Tello myTello = Tello() myTello.connect() myTello.takeoff() myTello.move_up(30) myTello.move_down(30) myTello.move_up(50) myTello.move_down(50) myTello.move_up(50) myTello.move_down(50) myTello.land()
  • 30. 파이썬 함수 이용하기 : def from djitellopy import Tello myTello = Tello() myTello.connect() myTello.takeoff() myTello.move_up(30) myTello.move_down(30) myTello.move_up(30) myTello.move_down(30) myTello.move_up(30) myTello.move_down(30) myTello.land() def move_up_down(t): myTello.move_up(t) myTello.move_down(t) for i in range(3): t = 30 move_up_down(t)
  • 31. 실습 04 • takeoff -> fwd(40) -> fwd(40) -> fwd(40) -> cw(180) -> fwd(40) -> fwd(40) -> fwd(40) -> cw(180) -> land • fwd(40)을 반복문으로 구현해 보자
  • 32. input() 함수를 사용한 드론 제어 from djitellopy import tello myTello = tello.Tello() myTello.connect() battery_level = tello.get_battery() print(battery_level) while True: command = int(input("Enter Command!")) print(command, end="n") if (command == 1): myTello.takeoff() elif (command == 2): myTello.move_up(30) elif (command == 3): myTello.move_down(30) elif (command == 4): myTello.land() else: break print("Drone mission completed!")
  • 33. 실습 05 : input() 함수를 이용한 드론 조정기 만들기 1. Takeoff() 2. move_up(20) 3. move_down(20) 4. move_left(20) 5. move_right(20) 6. move_forward(20) 7. move_backward(20) 8. rotate_clockwise(90) 9. rotate_counter_clockwose(90) 10. flip_back() 11. flip_forward() 12. flip_left() 13. flip_right() 14. land()
  • 34. 실습 06 : cross flight 미션
  • 35. 실습 06 : cross flight 미션 from djitellopy import Tello import time print("Create Tello object") tello = Tello() print("Connect to Tello Drone") tello.connect() battery_level = tello.get_batte ry() print(battery_level) print("Takeoff!") tello.takeoff() time.sleep(1) travel_distance_cm = 50 #tello.go_xyz_speed(x,y,z, speed) # x - (+)foward/(-)backwards # y - (+)left/(-)right # z - (+)up/(-)down tello.go_xyz_speed(0, 0, travel_distance_cm, 20) print("sleep") time.sleep(0.5) tello.go_xyz_speed(0, travel_distance_cm, -travel_distanc e_cm, 20) print("sleep") time.sleep(0.5) tello.go_xyz_speed(0, 0, travel_distance_cm, 20) print("sleep") time.sleep(0.5) # x - (+)foward/(-)backwards # y - (+)left/(-)right # z - (+)up/(-)down tello.go_xyz_speed(0, -travel_distance_cm, -travel_distan ce_cm, 20) print("sleep") time.sleep(0.5) print("landing")
  • 36. Opencv를 이용한 드론의 이미지, 동영상 처리 https://opencv.org/
  • 37. 드론 사진 촬영, 저장하기 import cv2 from djitellopy import Tello tello = Tello() tello.connect() tello.streamon() frame_read = tello.get_frame_read() tello.takeoff() cv2.imwrite("picture.png", frame_read.frame) tello.land()
  • 38. 드론 비디오 촬영, 전송 from djitellopy import tello import cv2 import time tello = tello.Tello() tello.connect() battery_level = tello.get_battery() print(f"Battery Life Percentage: {battery_level}") time.sleep(2) print("Turn Video Stream On") tello.streamon() # read a single image from the Tello video feed print("Read Tello Image") frame_read = tello.get_frame_read() print(type(frame_read)) time.sleep(2) while True: # read a single image from the Tello video feed print("Read Tello Image") tello_video_image = frame_read.frame # use opencv to write image if tello_video_image is not None: cv2.imshow("TelloVideo", tello_video_image) if cv2.waitKey(1) & 0xFF == ord('q'): break tello.streamoff() cv2.destroyWindow('TelloVideo') cv2.destroyAllWindows()
  • 39. 드론 키보드 제어하기 • manual-control-opencv from djitellopy import Tello import cv2, math, time tello = Tello() tello.connect() tello.streamon() frame_read = tello.get_frame_read() while True: img = frame_read.frame cv2.imshow("drone", img) key = cv2.waitKey(1) & 0xff if key == 27: # ESC break elif key == ord('t'): tello.takeoff() elif key == ord('w'): tello.move_forward(30) elif key == ord('s'): tello.move_back(30) elif key == ord('a'): tello.move_left(30) elif key == ord('d'): tello.move_right(30) elif key == ord('e'): tello.rotate_clockwise(30) elif key == ord('q'): tello.rotate_counter_clockwise(30) elif key == ord('r'): tello.move_up(30) elif key == ord('f'): tello.move_down(30) tello.land() cv2.destroyAllWindows()
  • 40. 실습 04 • ‘드론 키보드 제어하기’를 드론 카메라 대신, PC 웹캠을 사용하 여 PC에서 비디오 스트림을 보여 주도록 만드시오 • cv2.VideoCapture(0) • ret, frame = cap.read() • cv2.imshow(“Video”, frame) • https://github.com/DIT-AI-Drone- Course/SOURCE/blob/main/take_picture_opencv.py
  • 42. Opencv 기초 • https://opencv.org/ • % pip install opencv-python 혹은 파이참 add(+) opencv-python
  • 43. 파이썬 Opencv 모듈 설치 • 파이참 • 설정 -> 프로젝트 -> Python 인터프리터 -> + -> opencv-python
  • 44. 드론 사진 촬영, 저장하기 import cv2 from djitellopy import Tello battery_level = tello.get_battery() print(battery_level) tello = Tello() tello.connect() tello.streamon() frame_read = tello.get_frame_read() tello.takeoff() cv2.imwrite("picture.png", frame_read.frame) tello.land()
  • 45. Opencv로 드론 비디오 읽기, 보기 from djitellopy import tello import cv2 import time tello = tello.Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) print("Turn Video Stream On") tello.streamon() time.sleep(2) while True: # read a single image from the Tello video feed frame_read = tello.get_frame_read() tello_video_image = frame_read.frame # 이미지 크기 조정 “ resize() image = cv2.resize(tello_video_image, (360, 240)) # use opencv to write image if image is not None: cv2.imshow("TelloVideo", image) if cv2.waitKey(1) & 0xFF == ord('q'): break tello.streamoff() cv2.destroyWindow('TelloVideo') cv2.destroyAllWindows()
  • 46. 드론 비디오 촬영, 전송 : Opencv 키보드 제어 from djitellopy import tello import cv2 import time tello = tello.Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) time.sleep(2) tello.streamon() frame_read = tello.get_frame_read() while True: frame = frame_read.frame frame = cv2.resize(frame, (360*2, 240*2)) # 이미지 크기 조정 while True: frame = frame_read.frame if frame is not None: cv2.imshow("TelloVideo", frame) k = cv2.waitKey(5) & 0xFF if k == ord('q'): break elif k == ord('t'): tello.takeoff() elif k == ord('u'): tello.move_up(50) elif k == ord('c'): tello.rotate_clockwise(360) elif k == ord('l'): tello.land() else : print(‘no key!!!’) tello.streamoff() cv2.destroyWindow('TelloVideo') cv2.destroyAllWindows()
  • 47. Opencv로 드론 키보드 제어하기 • manual-control-opencv from djitellopy import Tello import cv2, time tello = Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) tello.streamon() frame_read = tello.get_frame_read() frame = cv2.resize(frame, (360*2, 240*2)) while True: img = frame_read.frame cv2.imshow("drone", img) key = cv2.waitKey(1) & 0xff if key == ord(‘q’): break elif key == ord('t'): tello.takeoff() elif key == ord(‘f'): tello.move_forward(30) elif key == ord(‘b'): tello.move_back(30) elif key == ord(‘l'): tello.move_left(30) elif key == ord(‘r'): tello.move_right(30) elif key == ord(‘c'): tello.rotate_clockwise(30) elif key == ord(‘r'): tello.rotate_counter_clockwise(30) elif key == ord(‘u'): tello.move_up(30) elif key == ord(‘d'): tello.move_down(30) tello.streamoff() cv2.destroyWindow(‘drone') cv2.destroyAllWindows() • 소스 코드 : https://github.com/damiafuentes/DJITelloPy/ blob/master/examples/manual-control-opencv.py
  • 48. 드론이 촬영/저장 하면서 동시에 비행하기 : 쓰레드(Thread) import time, cv2 from threading import Thread from djitellopy import Tello tello = Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) keepRecording = True tello.streamon() frame_read = tello.get_frame_read() def videoRecorder(): height, width, _ = frame_read.frame.shape # create a VideoWrite object, recoring to ./video.avi video = cv2.VideoWriter('video3.avi', cv2.VideoWriter_fourcc(*'XVID'), 30, (width, height)) while keepRecording: tello_video_image = frame_read.frame tello_video_image = cv2.resize(tello_video_image, (360 * 2, 240 * 2)) # PC에 Tello 촬영 동영상 저장 video.write(frame_read.frame) if tello_video_image is not None: cv2.imshow('video', tello_video_image) time.sleep(1 / 30) if cv2.waitKey(1) & 0xFF == ord('q'): cv2.destroyWindow('video') cv2.destroyAllWindows() # we need to run the recorder in a seperate thread recorder = Thread(target=videoRecorder) recorder.start() tello.takeoff() tello.move_up(30) tello.rotate_counter_clockwise(360) tello.land() keepRecording = False recorder.join() • 소스 코드 다운로드 : https://drive.google.com/file/d/1jZD-DjCZK8cVg1r-20hhr4-RcYzW9-5-/view?usp=sharing
  • 49. 파이썬 기반 AI 드론 코딩
  • 51. • pre-training model 다운로드 • https://github.com/opencv/opencv/blob/master/data/haarcascades 얼굴 인식하기 : Cascade Classifier
  • 52. 얼굴 인식하기 : Cascade Classifier import cv2 from djitellopy import tello tello = tello.Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) tello.streamon() while True: img = tello.get_frame_read().frame img = cv2.resize(img, (360*2, 240*2)) faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(imgGray, 1.3, 5) for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) cv2.imshow('frame',img) if cv2.waitKey(1) & 0xFF == ord('q'): break tello.streamoff() cv2.destroyAllWindows()
  • 53. 얼굴 인식하기 : Cascade Classifier import cv2 from djitellopy import tello tello = tello.Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) tello.streamon() while True: img = tello.get_frame_read().frame img = cv2.resize(img, (360, 240)) faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(imgGray, 1.2, 8) for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) cx = x + w // 2 cy = y + h // 2 area = w * h cv2.circle(img, (cx, cy), 5, (0, 255, 0), cv2.FILLED) print('area =', area) cv2.imshow('frame',img) if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows() * 소스 코드 : https://drive.google.com/file/d/1jZLuuovY-tWJdwy1LYD4knpCQkvAjzxk/view?usp=sharing * haarcascade_frontalface_default.xml 파일 : https://drive.google.com/file/d/1j_Hjo0N6v0HtL1F55ekFBbQ6yxKT3SrQ/view?usp=sharing
  • 54. 얼굴 추적 드론의 원리를 생각해 봅시다
  • 55. Face Tracking 드론 제어 • back, forward • ccw, cw • up, down
  • 56.
  • 57. 인식된 얼굴 중심점(cx, cy)과 전체 프레임 중심점(tcx, tcy) 차이 import cv2 from djitellopy import tello tello = tello.Tello() tello.connect() battery_level = tello.get_battery() print(battery_level) tello.streamon() while True: img = tello.get_frame_read().frame img = cv2.resize(img, (360*2, 240*2)) faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(imgGray, 1.3, 5) if len(faces) == 1: print("face found") print('faces', faces) else: print("face not found") # 전체 화면의 중심점(center) tcx = 360 tcy = 240 cv2.circle(img, (tcx, tcy), 10, (255, 0, 0), cv2.FILLED) # 인식된 얼굴 사각형 박스 그리기 for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2) cx = x + w // 2 cy = y + h // 2 area = w * h cv2.circle(img, (cx, cy), 10, (0, 255, 0), cv2.FILLED) print('area =', area) # 전체 이미지 중심과 얼굴 이지미 중심 간의 선 그리기기 cv2.line(img, (cx, cy), (tcx, tcy), (255, 0, 0), 2) cv2.imshow('frame',img) if cv2.waitKey(1) & 0xFF == ord('q'): break tello.streamoff() cv2.destroyAllWindows()
  • 58. forward/ backward 제어 # 얼굴 이미지 크기 : z_area = offset_z offset_z = w * h # 얼굴 이미지 크기 update 및 forward/ backward 제어 def adjust_tello_position(offsetz): f not 15000 <= offset_z <= 30000 and offset_z != 0: if offset_z < 15000: tello.move_forward(20) elif offset_z > 30000: tello.move_back(20) 실습 소스 : https://drive.google.com/file/d/1fJn9bOhB9cEKs71fDCtqzvWxQfNcb4z5/view?usp=sharing
  • 59. left/ right 제어 offset_x = face_center_x - center_x def adjust_tello_position(offset_x): """ Adjusts the position of the tello drone based on the offset values given from th e frame :param offset_x: Offset between center and face x coordinates """ if not -90 <= offset_x <= 90 and offset_x != 0: # offset_x가 음수이면 시계 반대 방향으로 일정 거리 만큼 이동 if offset_x < 0: tello.rotate_counter_clockwise(10) # offset_x가 양수이면 시계 방향으로 일정 거리 만큼 이동 elif offset_x > 0: tello.rotate_clockwise(10) 실습 소스 : https://drive.google.com/file/d/1WXTTag3aDv66SXSCYzapRxOcCA3PNnSK/view?usp=sharing
  • 60. up/ down 제어 # Add 30 so that the drone covers as much of the subject as possible offset_y = face_center_y - center_y - 30 """ Adjusts the position of the tello drone based on the offset values given from the frame :param offset_y: Offset between center and face y coordinates """ if not -70 <= offset_y <= 70 and offset_y != -30: if offset_y < 0: print('move up') tello.move_up(20) elif offset_y > 0: print('move down') tello.move_down(20) 실습 소스 : https://drive.google.com/file/d/1WXTTag3aDv66SXSCYzapRxOcCA3PNnSK/view?usp=sharing
  • 61. Face following 제어 소스 코드 : https://drive.google.com/file/d/1f4Xcq8W4HL7tRSILb-hXrV9Jd-gywPPp/view?usp=sharing
  • 62. Face Detection AI 알고리즘 • Haar Cascade • https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcas cade_frontalface_default.xml • Dlib : HOG + CNN • https://github.com/davisking/dlib • MTCNN • https://github.com/ipazc/mtcnn • OpenCV DNN : Caffe based DNN • https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector • YOLO • https://velog.io/@hhhong/Object-Detection-with-YOLO
  • 63. AI 드론 프로젝트 • PID 제어 • https://github.com/ivmech/ivPID • Custom 훈련 데이터 • 전이학습(fine tuning) • PoseNet • 제스쳐 인식 제어 • Dlib • facial landmark 탐지 • YOLO • 실시간 객체 탐지
  • 64. 손 제스쳐 기반 드론 제어 • MediaPipe • https://google.github.io/mediapipe/
  • 65. 참고 자료 • https://www.youtube.com/watch?v=LmEcyQnfpDA&t=3576s • https://github.com/juanmapf97/Tello-Face-Recognition • https://google.github.io/mediapipe/ • https://www.droneblocks.io/