def main(): drone = tellopy.Tello() try: drone.connect() drone.wait_for_connection(60.0) container = av.open(drone.get_video_stream()) # skip first 300 frames frame_skip = 300 while True: for frame in container.decode(video=0): if 0 < frame_skip: frame_skip = frame_skip - 1 continue start_time = time.time() image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2GRAY) cv2.imshow('Original', image) cv2.imshow('Canny', cv2.Canny(image, 100, 200)) cv2.waitKey(1) frame_skip = int((time.time() - start_time) / frame.time_base) except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) print(ex) finally: drone.quit() cv2.destroyAllWindows()
def recognize_face(self): """ Wait until a face is recognized. If openCV is configured, always return true :return: """ if vision_enabled is False: # if opencv is not able to be imported, always return True return True face_cascade = cv2.CascadeClassifier(self.facial_recognition_model) video_capture = cv2.VideoCapture(0) while True: # Capture frame-by-frame ret, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags=cv2.cv.CV_HAAR_SCALE_IMAGE) if len(faces) > 0: # When everything is done, release the capture video_capture.release() cv2.destroyAllWindows() return True
# -*- coding: utf-8 -*- """ Created on Sun Jul 30 00:30:22 2017 @author: RSF """ import numpy as np import opencv as cv2 cap = cv2.VideoCapture(0) while(True): ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()