# function to uncover payload
def strip_packet(m):
    ba = bitstring.BitArray(bytes=m)  # encode string and turn to bit array
    pt = ba[9:16]  # type of packet contents
    # cc = ba[4:8]  # number of extra header fields
    print(pt.uint)  # for testing purposes
    # return ba[(12 + cc) * 8:]  # bit contents


# create drone and start video
drone = Bebop()
drone.connect(10)
drone.set_video_resolutions("rec1080_stream480")
drone.set_video_framerate("24_FPS")
drone.start_video_stream()

# create socket of required type, and bind to port
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # opens with ipv4 address and reads UDP packet
sock.bind(('192.168.42.63', 55004))  # binds machine to port

# receive packet and get payload
for _ in range(10):
    msg = sock.recv(4096)
    strip_packet(msg)
    # payload = stripPacket(msg)

'''The received contents are H.264 encoded video. While we can put packets together, there doesn't seem to be 
documentation on manual conversion to video or images, as all methods result in using opencv or other libraries/apps. 
Hence we adopt the opencv approach. This code can stay because it required far too much research to throw away. '''
示例#2
0
文件: pyparrot2.py 项目: Yeb02/TIPE
        if (img is not None):
            img = Canny(img)
            filename = "test_image_%06d.png" % self.index
            cv2.imwrite(filename, img)
            self.index +=1


# make my bebop object
bebop = Bebop()

# connect to the bebop
success = bebop.connect(5)

if (success):
    # start up the video
    bebop.set_video_framerate("24_FPS")
    bebop.set_video_resolutions("rec720_stream720")
    bebopVision = DroneVision(bebop, is_bebop=True)
    bebopVision.cleanup_old_images = True
    userVision = UserVision(bebopVision)
    bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None)
    success = bebopVision.open_video()

    # if (success):
    #     print("Vision successfully started!")
    #     print("Fly me around by hand!")
    #     bebop.smart_sleep(1)
    #     print("Moving the camera using velocity")
    #     bebop.pan_tilt_camera_velocity(pan_velocity=0, tilt_velocity=-2, duration=4)
    #     bebop.smart_sleep(1)
    #     print("Finishing demo and stopping vision")