示例#1
0
    def camera_callback(self, msg):
        if msg.action & 0b001:  # take picture
            self.drone(
                camera.take_photo(cam_id=0)
            )  # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.take_photo
        if msg.action & 0b010:  # start recording
            self.drone(camera.start_recording(cam_id=0)).wait(
            )  # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.start_recording
        if msg.action & 0b100:  # stop recording
            self.drone(camera.stop_recording(cam_id=0)).wait(
            )  # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.stop_recording

        self.drone(
            gimbal.
            set_target(  # https://developer.parrot.com/docs/olympe/arsdkng_gimbal.html#olympe.messages.gimbal.set_target
                gimbal_id=0,
                control_mode='position',  # {'position', 'velocity'}
                yaw_frame_of_reference='none',
                yaw=0.0,
                pitch_frame_of_reference=self.
                gimbal_frame,  # {'absolute', 'relative', 'none'}
                pitch=msg.pitch,
                roll_frame_of_reference=self.
                gimbal_frame,  # {'absolute', 'relative', 'none'}
                roll=msg.roll))

        self.drone(
            camera.
            set_zoom_target(  # https://developer.parrot.com/docs/olympe/arsdkng_camera.html#olympe.messages.camera.set_zoom_target
                cam_id=0,
                control_mode='level',  # {'level', 'velocity'}
                target=msg.zoom))  # [1, 3]
示例#2
0
def take_photo_burst(drone):

    photo_saved = drone(photo_progress(result='photo_saved', _policy='wait'))
    drone(take_photo(cam_id=0)).wait()
    photo_saved.wait()
    media_id = photo_saved.received_events().last().args["media_id"]

    # download the photos associated with this media id
    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()
    # download_dir = tempfile.mkdtemp()
    download_dir = "../images"

    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])
        image_response.raise_for_status()
        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)

        # parse the xmp metadata
        with open(download_path, "rb") as image_file:
            image_data = image_file.read()
            image_xmp_start = image_data.find(b"<x:xmpmeta")
            image_xmp_end = image_data.find(b"</x:xmpmeta")
            image_xmp = ET.fromstring(
                image_data[image_xmp_start:image_xmp_end + 12])
            for image_meta in image_xmp[0][0]:
                xmp_tag = re.sub(r"{[^}]*}", "", image_meta.tag)
                xmp_value = image_meta.text
                # only print the XMP tags we are interested in
                if xmp_tag in XMP_TAGS_OF_INTEREST:
                    print(resource["resource_id"], xmp_tag, xmp_value)
示例#3
0
文件: photo.py 项目: ndessart/olympe
def take_photo_burst(drone):
    # take a photo burst and get the associated media_id
    photo_saved = drone(photo_progress(result="photo_saved", _policy="wait"))
    drone(take_photo(cam_id=0)).wait()
    if not photo_saved.wait(_timeout=30).success():
        return
    media_id = photo_saved.received_events().last().args["media_id"]
    print("Photo burst resources: {}".format(", ".join(
        r.resource_id for r in drone.media.resource_info(media_id=media_id))))

    # download the photos associated with this media id
    download_dir = tempfile.mkdtemp(prefix="olympe_photo_example")
    resources = drone.media.download_media(download_dir,
                                           media_id,
                                           integrity_check=True)
    for status, resource_path, resource in resources:
        if not status:
            print("Failed to download {}".format(resource.resource_id))
            continue
        # parse the xmp metadata
        with open(resource_path, "rb") as image_file:
            image_data = image_file.read()
            image_xmp_start = image_data.find(b"<x:xmpmeta")
            image_xmp_end = image_data.find(b"</x:xmpmeta")
            image_xmp = ET.fromstring(
                image_data[image_xmp_start:image_xmp_end + 12])
            for image_meta in image_xmp[0][0]:
                xmp_tag = re.sub(r"{[^}]*}", "", image_meta.tag)
                xmp_value = image_meta.text
                # only print the XMP tags we are interested in
                if xmp_tag in XMP_TAGS_OF_INTEREST:
                    print(resource.resource_id, xmp_tag, xmp_value)
示例#4
0
def take_photo_burst(drone):
    # take a photo burst and get the associated media_id

    d_actn = drone(take_photo(cam_id=0)).wait()
    print(colored((d_actn.success()), "cyan"))

    photo_saved = drone(photo_progress(result="photo_saved", _policy="wait"))
    photo_saved.wait()

    media_id = photo_saved.received_events().last().args["media_id"]
    print(colored((media_id), "green"))

    os.chdir("/home/rnallapu/code/Results")

    # download the photos associated with this media id
    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()

    download_dir = tempfile.mkdtemp()
    Res_dir = filecreation()

    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])
        # download_path = os.path.join(Res_dir, resource["resource_id"])
        image_response.raise_for_status()

        print(colored((download_dir), "red"))

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)

        shutil.copy2(download_path, Res_dir)
        print(colored(("Photos Copied !!"), "cyan"))
示例#5
0
def take_photo_burst(drone):
    # take a photo burst and get the associated media_id
    photo_saved = drone(photo_progress(result="photo_saved", _policy="wait"))
    drone(take_photo(cam_id=0)).wait()
    if not photo_saved.wait(_timeout=30).success():
        assert False, "take_photo timedout"
    photo_progress_info = photo_saved.received_events().last().args
    media_id = photo_progress_info["media_id"]
    photo_count = photo_progress_info["photo_count"]
    # download the photos associated with this media id
    drone.media.download_dir = tempfile.mkdtemp(prefix="olympe_photo_example")
    logger.info("Download photo burst resources for media_id: {} in {}".format(
        media_id,
        drone.media.download_dir,
    ))
    media_download = drone(download_media(media_id, integrity_check=True))
    # Iterate over the downloaded media on the fly
    resources = media_download.as_completed(expected_count=photo_count,
                                            timeout=60)
    resource_count = 0
    for resource in resources:
        logger.info("Resource: {}".format(resource.resource_id))
        if not resource.success():
            logger.error("Failed to download {}".format(resource.resource_id))
            continue
        resource_count += 1
        # parse the xmp metadata
        with open(resource.download_path, "rb") as image_file:
            image_data = image_file.read()
            image_xmp_start = image_data.find(b"<x:xmpmeta")
            image_xmp_end = image_data.find(b"</x:xmpmeta")
            if image_xmp_start < 0 or image_xmp_end < 0:
                logger.error("Failed to find XMP photo metadata {}".format(
                    resource.resource_id))
                continue
            image_xmp = ET.fromstring(
                image_data[image_xmp_start:image_xmp_end + 12])
            for image_meta in image_xmp[0][0]:
                xmp_tag = re.sub(r"{[^}]*}", "", image_meta.tag)
                xmp_value = image_meta.text
                # only print the XMP tags we are interested in
                if xmp_tag in XMP_TAGS_OF_INTEREST:
                    logger.info("{} {} {}".format(resource.resource_id,
                                                  xmp_tag, xmp_value))
    logger.info("{} media resource downloaded".format(resource_count))
    assert resource_count == 14, "resource count == {} != 14".format(
        resource_count)
    assert media_download.wait(1.).success(), "Photo burst media download"
示例#6
0
def take_photo_burst_Move(drone, th_mov, th_R0, dxm):
    # take a photo burst and get the associated media_id

    xc, yc, zc =  R3_Mat_Cords(th_R0, dxm)
    photo_saved = drone(photo_progress(result="photo_saved", _policy="wait"))
    drone(take_photo(cam_id=0) & moveBy(xc, yc, zc, th_mov)).wait()
    photo_saved.wait()
    media_id = photo_saved.received_events().last().args["media_id"]

    # download the photos associated with this media id
    media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
    media_info_response.raise_for_status()
    os.chdir("/home/rnallapu/code/Results")
    download_dir = tempfile.mkdtemp()
    Res_dir = filecreation()

    #tempfile.gettempdir()
    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])

        print('Hello')

        print(download_path)
        image_response.raise_for_status()

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)

        # parse the xmp metadata
        with open(download_path, "rb") as image_file:
            image_data = image_file.read()
            image_xmp_start = image_data.find(b"<x:xmpmeta")
            image_xmp_end = image_data.find(b"</x:xmpmeta")
            image_xmp = ET.fromstring(image_data[image_xmp_start : image_xmp_end + 12])
            for image_meta in image_xmp[0][0]:
                xmp_tag = re.sub(r"{[^}]*}", "", image_meta.tag)
                xmp_value = image_meta.text
                # only print the XMP tags we are interested in
                if xmp_tag in XMP_TAGS_OF_INTEREST:
                    print(resource["resource_id"], xmp_tag, xmp_value)

    #
        #shutil.copy2(download_path, "/home/rnallapu/code/Photos/")
        shutil.copy2(download_path, Res_dir)
示例#7
0
文件: media.py 项目: ndessart/olympe
def main(drone, media=None):
    drone.connect()
    setup_photo_burst_mode(drone)
    if media is None:
        assert drone.media_autoconnect
        media = drone.media
    media.download_dir = tempfile.mkdtemp(prefix="olympe_media_example_")
    media.integrity_check = True
    logger.info("waiting for media resources indexing...")
    if not media(indexing_state(state="indexed")).wait(_timeout=60).success():
        logger.error("Media indexing timed out")
        return
    logger.info("media resources indexed")
    with MediaEventListener(media):
        photo_saved = drone(
            photo_progress(result="photo_saved", _policy="wait"))
        drone(take_photo(cam_id=0)).wait()
        if not photo_saved.wait(_timeout=30).success():
            logger.error("Photo not saved: {}".format(photo_saved.explain()))
示例#8
0
    def takePhoto(self, longitude, latitude, altitude=-1):
        drone_location = self.drone.get_state(GpsLocationChanged)
        self.setup_photo_mode()
        print(drone_location)
        self.flyTo(longitude, latitude, altitude)
        # take a photo burst and get the associated media_id
        photo_saved = self.drone(
            photo_progress(result="photo_saved", _policy="wait"))
        self.drone(take_photo(cam_id=0)).wait()
        photo_saved.wait()
        media_id = photo_saved.received_events().last().args["media_id"]
        print(media_id)
        # download the photos associated with this media id
        media_info_response = requests.get(ANAFI_MEDIA_API_URL + media_id)
        media_info_response.raise_for_status()
        download_dir = self.images_path
        for resource in media_info_response.json()["resources"]:
            image_response = requests.get(ANAFI_URL + resource["url"],
                                          stream=True)
            download_path = os.path.join(download_dir, resource["resource_id"])
            print(download_path)
            image_response.raise_for_status()
            with open(download_path, "wb") as image_file:
                shutil.copyfileobj(image_response.raw, image_file)

            # parse the xmp metadata
            with open(download_path, "rb") as image_file:
                image_data = image_file.read()
                image_xmp_start = image_data.find(b"<x:xmpmeta")
                image_xmp_end = image_data.find(b"</x:xmpmeta")
                image_xmp = ET.fromstring(
                    image_data[image_xmp_start:image_xmp_end + 12])
                for image_meta in image_xmp[0][0]:
                    xmp_tag = re.sub(r"{[^}]*}", "", image_meta.tag)
                    xmp_value = image_meta.text
                    # only print the XMP tags we are interested in
                    if xmp_tag in XMP_TAGS_OF_INTEREST:
                        print(resource["resource_id"], xmp_tag, xmp_value)
        return download_path
示例#9
0
drone(
    set_camera_mode(cam_id=0, value=1)
).wait()
#Set photo mode
drone(
    set_photo_mode(cam_id=0, mode=0, format=0, file_format=0, burst=0, bracketing=0, capture_interval=0)
).wait()
# #Take picture
# drone(
#     take_photo(cam_id=0)
# ).wait()
print("*******************************************************************************************************")
print("TAKING PICTURE")
print("*******************************************************************************************************") 
photo_saved = drone(photo_progress(result="photo_saved", _policy="wait"))
drone(take_photo(cam_id=0)).wait()
photo_saved.wait()
media_id = photo_saved.received_events().last().args["media_id"]
#Go to HOME
print("*******************************************************************************************************")
print("GOING TO HOME")
print("*******************************************************************************************************") 
drone(
    moveTo(latitude=homeLatitude,longitude=homeLongitude,altitude=homeAltitude, orientation_mode=0, heading=0)
    >> FlyingStateChanged(state="hovering", _timeout=5)
).wait()
drone(Landing()).wait()
drone.disconnection()

#Save photo to local storage
print("*******************************************************************************************************")
示例#10
0
def take_Map_Photo_Move(drone, th_mov, th_gim, th_R0,  xf, dxm, dzm):
    photo_saved = drone(photo_progress(result="photo_saved", _policy="wait"))

    # Pass - 1: 
    drone(moveBy(0, 0, dzm, 0) 
    >> FlyingStateChanged(state="hovering", _timeout=5)).wait() # Initial Height
    m_AR = []
    AMPU_ID = []
    
    drone(gimbal.set_target(
        gimbal_id=0,
        control_mode="position",
        yaw_frame_of_reference="relative",
        yaw=0.0,
        pitch_frame_of_reference="relative",
        pitch=th_gim,
        roll_frame_of_reference="relative",
        roll=0.0)
        >> olympe.messages.gimbal.attitude(pitch_relative=th_gim, _timeout=5)
    ).wait()
    
    D_th = th_mov 
    x_arr  = arange(0, xf, dxm)
    xlen   = len(x_arr)
    th_arr1 = linspace(0, D_th, xlen)
    th_arr  = th_arr1 + th_R0
    dth = th_arr1[1]

    # take a photo burst and get the associated media_id


    for ix in range(0, xlen-1):
        xc, yc, zc =  R3_Mat_Cords(th_arr[ix], dxm)
        drone(
            take_photo(cam_id=0) & moveBy(xc, yc, zc, dth)
        >> FlyingStateChanged(state="hovering", _timeout=5)).wait()
        photo_saved.wait()
        idp = photo_saved.received_events().last().args["media_id"]
        m_AR.append(idp)
        
    # Pass - 2: 
    drone(moveBy(0, 0, -2*dzm, 0)
    >> FlyingStateChanged(state="hovering", _timeout=5)).wait() # Initial Height
    
    drone(gimbal.set_target(
        gimbal_id=0,
        control_mode="position",
        yaw_frame_of_reference="relative",
        yaw=0.0,
        pitch_frame_of_reference="relative",
        pitch=-2*th_gim,
        roll_frame_of_reference="relative",
        roll=0.0)
        >> olympe.messages.gimbal.attitude(pitch_relative=-2*th_gim, _timeout=5)
    ).wait()
    
    D_th2 = -th_mov 
    th_arr2 = linspace(0, D_th2, xlen)
    dth2 = th_arr2[1]


    # take a photo burst and get the associated media_id
    for ix1 in range(0, xlen-1):
        xc, yc, zc =  R3_Mat_Cords(th_arr[xlen-ix1-1], -dxm)
        drone(
            take_photo(cam_id=0) & moveBy(xc, yc, zc, dth2)
        >> FlyingStateChanged(state="hovering", _timeout=5)).wait() 
        photo_saved.wait()
        idp = photo_saved.received_events().last().args["media_id"]
        m_AR.append(idp)   

    #media_id = photo_saved.received_events().last().args["media_id"]


    nph = len(m_AR)
    ## HEre

    # download the photos associated with this media id
    os.chdir("/home/rnallapu/code/Results")

    #media_info_response = requests.get(ANAFI_MEDIA_API_URL + m_AR)
    #media_info_response = requests.get(ANAFI_MEDIA_API_URL.join(m_AR))
    for inph in range(0, nph-1):
        AMPU_ID.append(ANAFI_MEDIA_API_URL + m_AR[inph])
    
    media_info_response = requests.get(AMPU_ID[2])
    media_info_response.raise_for_status()
    print(AMPU_ID)
    print('Action Completed')
    

    download_dir = tempfile.mkdtemp()
    Res_dir = filecreation()
    

    #tempfile.gettempdir()
    for resource in media_info_response.json()["resources"]:
        image_response = requests.get(ANAFI_URL + resource["url"], stream=True)
        download_path = os.path.join(download_dir, resource["resource_id"])

        print('Hello')
        print(download_path)
        image_response.raise_for_status()

        with open(download_path, "wb") as image_file:
            shutil.copyfileobj(image_response.raw, image_file)

        #shutil.copy2(download_path, "/home/rnallapu/code/Photos/")
        shutil.copy2(download_path, Res_dir)