コード例 #1
0
    def triggerCamera():

        camera = ptpy.PTPy()
        with camera.session():
            capture = camera.initiate_capture()
            print(capture)
            evt = camera.event()
            if evt:
                print(evt)
            print("-------")
コード例 #2
0
def get_photos(progress_bar):
    """
    Downloads photos on sd card in nikon D800

    :param source_text:
    :return:
    """
    # setup folder naming-------------------------------------------------------------------------
    i = 100  # index for folder name
    folder = ''
    # sd card ParentObjects are in format 3#########
    sd = 300000000  # use sd = 200000000 if only sd card in camera (Careful NOT tested)
    try:
        camera = pt.PTPy()
    except pt.ptp.PTPError:  # camera not connected
        return

    with camera.session():
        handles = camera.get_object_handles(0, all_storage_ids=True, all_formats=True, )
        parent_objs = []  # a list of sd card folder ids

        import_folder = os.path.join('G:', 'Imports')
        step = trunc(100 / len(handles))
        # loop through the list of photos on the sd card downloading as necessary
        for handle in handles:
            progress_bar.step(step)
            progress_bar.update()
            info = camera.get_object_info(handle)
            parent_obj = info.ParentObject
            if not (parent_obj // sd):  # sd card ParentObjects are in format 3########
                pass
            else:

                # map sd card folder structure to import folder
                if parent_obj not in parent_objs:  # is this a new sd folder

                    # add the folder id  to list of folder ids
                    parent_objs.append(parent_obj)

                    # create the local folder mapped from the sd folder
                    while True:
                        folder = '{:3}ND800'.format(i)
                        try:
                            os.mkdir(os.path.join(import_folder, folder))
                            i += 1  # increment the folder name ready for the next one
                            break
                        except FileExistsError:  # that folder already exists so increment the name and try again
                            i += 1

                #  download the photo
                download_photo(camera=camera,
                               handle=handle,
                               img=os.path.join(import_folder, folder, info.Filename),
                               )
コード例 #3
0
#!/usr/bin/env python
import ptpy

camera = ptpy.PTPy()
with camera.session():
    while True:
        evt = camera.event()
        if evt:
            print(evt)
コード例 #4
0
                    obj = camera.get_object(handle)
                    toc = time()
                    log.info('{}: {:.1f}MB/s'.format(
                        caminfo.SerialNumber,
                        len(obj.Data) / ((toc - tic) * 1e6)))
                    with open(info.Filename, mode='w') as f:
                        f.write(obj.Data)


# Find each connected USB camera try to instantiate it and set up a capture and
# download thread for it if successful.
threads = []
for i, device in enumerate(find_usb_cameras()):

    try:
        camera = ptpy.PTPy(device=device)
        info = camera.get_device_info()
        caminfo = (info.Manufacturer, info.Model, info.SerialNumber)
        if ('InitiateCapture' not in info.OperationsSupported
                or 'GetObject' not in info.OperationsSupported):
            raise Exception(
                '{} {} {} does not support capture or download...'.format(
                    *caminfo))
        log.info('Found {} {} {}'.format(*caminfo))
    except Exception as e:
        log.error(e)
        continue

    capture = Thread(name='PHOTO{:02}'.format(i),
                     target=capture_thread,
                     args=(camera, ))