Пример #1
0
def start_photobooth():
    ##for the first PIC
    preview(3,'r',1)
    if play_shutter_sound == 1:
        shutter_sound.play()

    #take the photos
    file_name=time.strftime("%d%m%Y_%H%M%S")
    for i, filename in enumerate(camera.capture_continuous(file_path + file_name + '-' + '{counter:02d}.jpg',use_video_port=False)):
        print(filename)

        if use_external_camera == 1:
            context = gp.gp_context_new()
            camera_ext = gp.check_result(gp.gp_camera_new())
            error = gp.gp_camera_init(camera_ext, context)
            if error != gp.GP_ERROR_MODEL_NOT_FOUND:
                gp.gp_camera_capture(camera_ext, gp.GP_CAPTURE_IMAGE)
            gp.gp_camera_exit(camera_ext)

        if i == total_pics-1:
            #GPIO.output(led1_pin,False);
            break
        preview(3,'r',i+2)
        if play_shutter_sound == 1:
            shutter_sound.play()

    #show photos
    for pNum in range (1,total_pics+1):
        displayImage(file_path + file_name + '-0' + str(pNum) + '.jpg')
        text = 'photo ' + str(pNum) + ' of ' + str(total_pics)
        drawText(small_font, text, clear_screen=False, color=(255,255,255), y=15)
        time.sleep(5)
Пример #2
0
def initializecamera():
    global camera #相机
    global back_path #背景图路径
    global img_back1 #背景图
    global image_width #相机预览图的宽
    global image_height #相机预览图的高
    global scale_factor #获取图像缩小的倍数
    global screen_width, screen_height

    Killgphoto2Process() #先停止gphoto2 运行线程

    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    camera_file = gp.check_result(gp.gp_camera_capture_preview(camera))
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    image = Image.open(io.BytesIO(file_data))
    frame = np.array(image)
    image_height, image_width = frame.shape[:2]     # 获得相机预览图片大小
    print('相机预览画面 宽/高=', image_width,'/', image_height)
    img_back1 = cv.imread(back_path)    # 绿幕背景图片
    img_back1 = cv.resize(img_back1,(image_width,image_height))  # 改变背景图片分辨率
    if image_width > 900:
        scale_factor = 0.5
    else:
        scale_factor = 1
Пример #3
0
def main():
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    text = gp.check_result(gp.gp_camera_get_summary(camera))
    print('Summary')
    print('=======')
    print(text.text)
    print('Abilities')
    print('=========')
    abilities = gp.check_result(gp.gp_camera_get_abilities(camera))
    print('model:', abilities.model)
    print('status:', abilities.status)
    print('port:', abilities.port)
    print('speed:', abilities.speed)
    print('operations:', abilities.operations)
    print('file_operations:', abilities.file_operations)
    print('folder_operations:', abilities.folder_operations)
    print('usb_vendor:', abilities.usb_vendor)
    print('usb_product:', abilities.usb_product)
    print('usb_class:', abilities.usb_class)
    print('usb_subclass:', abilities.usb_subclass)
    print('usb_protocol:', abilities.usb_protocol)
    print('library:', abilities.library)
    print('id:', abilities.id)
    print('device_type:', abilities.device_type)
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #4
0
    def __init__(self, resolution=(320, 240), framerate=32, **kwargs):
        print("Init camera")
        # SLR Setup
        self.shotRequested = False
        # GPhoto init / testing
        self.context = gp.gp_context_new()
        self.error, self.camera = gp.gp_camera_new()
        self.error = gp.gp_camera_init(self.camera, self.context)
        self.error, self.text = gp.gp_camera_get_summary(
            self.camera, self.context)

        # required configuration will depend on camera type!
        print('Checking camera config')
        self.config = gp.check_result(gp.gp_camera_get_config(self.camera))
        OK, image_format = gp.gp_widget_get_child_by_name(
            self.config, 'imageformat')
        if OK >= gp.GP_OK:
            value = gp.check_result(gp.gp_widget_get_value(image_format))
            if 'raw' in value.lower():
                print('Cannot preview raw images')
        # find the capture size class config item
        OK, capture_size_class = gp.gp_widget_get_child_by_name(
            self.config, 'capturesizeclass')
        if OK >= gp.GP_OK:
            value = gp.check_result(
                gp.gp_widget_get_choice(capture_size_class, 2))
            gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
            gp.check_result(gp.gp_camera_set_config(self.camera, config))

        self.frame = None
        self.shot = None
        self.stopped = False
Пример #5
0
def main():
    # use Python logging
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    # get user value
    if len(sys.argv) != 2:
        print('One command line parameter required')
        return 1
    try:
        value = int(sys.argv[1])
    except:
        print('Integer parameter required')
        return 1
    # open camera connection
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera))
    # find the capture target config item
    capture_target = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'capturetarget'))
    # check value in range
    count = gp.check_result(gp.gp_widget_count_choices(capture_target))
    if value < 0 or value >= count:
        print('Parameter out of range')
        return 1
    # set value
    value = gp.check_result(gp.gp_widget_get_choice(capture_target, value))
    gp.check_result(gp.gp_widget_set_value(capture_target, value))
    # set config
    gp.check_result(gp.gp_camera_set_config(camera, config))
    # clean up
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    text = gp.check_result(gp.gp_camera_get_summary(camera))
    print('Summary')
    print('=======')
    print(text.text)
    print('Abilities')
    print('=========')
    abilities = gp.check_result(gp.gp_camera_get_abilities(camera))
    print('model:', abilities.model)
    print('status:', abilities.status)
    print('port:', abilities.port)
    print('speed:', abilities.speed)
    print('operations:', abilities.operations)
    print('file_operations:', abilities.file_operations)
    print('folder_operations:', abilities.folder_operations)
    print('usb_vendor:', abilities.usb_vendor)
    print('usb_product:', abilities.usb_product)
    print('usb_class:', abilities.usb_class)
    print('usb_subclass:', abilities.usb_subclass)
    print('usb_protocol:', abilities.usb_protocol)
    print('library:', abilities.library)
    print('id:', abilities.id)
    print('device_type:', abilities.device_type)
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #7
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    computer_files = list_computer_files()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Getting list of files from camera...')
    camera_files = list_camera_files(camera)
    if not camera_files:
        print('No files found')
        return 1
    print('Copying files...')
    for path in camera_files:
        info = get_camera_file_info(camera, path)
        timestamp = datetime.fromtimestamp(info.file.mtime)
        folder, name = os.path.split(path)
        dest_dir = get_target_dir(timestamp)
        dest = os.path.join(dest_dir, name)
        if dest in computer_files:
            continue
        print('%s -> %s' % (path, dest_dir))
        if not os.path.isdir(dest_dir):
            os.makedirs(dest_dir)
        camera_file = gp.check_result(gp.gp_camera_file_get(
            camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
        gp.check_result(gp.gp_file_save(camera_file, dest))
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #8
0
async def capture(websocket):
    # Capture Image
    try:
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_init(camera))

        print('Capturing Image...')
        file_path = gp.check_result(
            gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
        print('Camera file path: {0}/{1}'.format(file_path.folder,
                                                 file_path.name))
        filename = get_next_filename(image_dir)
        target = os.path.join(image_dir, filename)

        print('Copying image to', target)
        camera_file = gp.check_result(
            gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                                  gp.GP_FILE_TYPE_NORMAL))
        gp.check_result(gp.gp_file_save(camera_file, target))
        gp.check_result(gp.gp_camera_exit(camera))

        if os.path.isdir(usb_dir):
            shutil.copy(target, os.path.join(usb_dir, filename))

        print('Image Ready!')
        await send_message({
            'event': 'imageReady',
            'filename': filename,
            'name': filename.split('.')[0]
        })

    except Exception as e:
        print("Error while trying to take photo: " + str(e))
        await send_message({'event': 'captureError', 'error': str(e)})
Пример #9
0
def main():
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Getting list of files')
    files = list_files(camera)
    if not files:
        print('No files found')
        return 1
    path = files[0]
    print('Copying %s to memory' % path)
    folder, name = os.path.split(path)
    camera_file = gp.check_result(
        gp.gp_camera_file_get(camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
    ##    # read file data using 'slurp' and a buffer allocated in Python
    ##    info = gp.check_result(
    ##        gp.gp_camera_file_get_info(camera, folder, name))
    ##    file_data = bytearray(info.file.size)
    ##    count = gp.check_result(gp.gp_file_slurp(camera_file, file_data))
    ##    print(count, 'bytes read')
    # or read data using 'get_data_and_size' which allocates its own buffer
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    data = memoryview(file_data)
    print(type(data), len(data))
    print(data[:10].tolist())
    image = Image.open(io.BytesIO(file_data))
    image.show()
    print('After deleting camera_file and file_data')
    del camera_file, file_data
    print(type(data), len(data))
    print(data[:10].tolist())
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #10
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    print('Getting list of files')
    files = list_files(camera, context)
    if not files:
        print('No files found')
        return 1
    path = files[0]
    print('Copying %s to memory' % path)
    folder, name = os.path.split(path)
    camera_file = gp.check_result(gp.gp_camera_file_get(
        camera, folder, name, gp.GP_FILE_TYPE_NORMAL, context))
    data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    print(type(data), len(data))
    if six.PY2:
        print(map(ord, data[0:10]))
        image = Image.open(StringIO.StringIO(data))
    else:
        print(data[0:10])
        image = Image.open(io.BytesIO(data))
    image.show()
    print('After deleting camera_file')
    del camera_file
    print(type(data), len(data))
    if six.PY2:
        print(map(ord, data[0:10]))
    else:
        print(data[0:10])
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #11
0
def main():
    logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    print("Getting list of files")
    files = list_files(camera, context)
    if not files:
        print("No files found")
        return 1
    path = files[0]
    print("Copying %s to memory" % path)
    folder, name = os.path.split(path)
    camera_file = gp.check_result(gp.gp_camera_file_get(camera, folder, name, gp.GP_FILE_TYPE_NORMAL, context))
    # read file data using 'slurp' and a buffer allocated in Python
    info = gp.check_result(gp.gp_camera_file_get_info(camera, folder, name, context))
    file_data = bytearray(info.file.size)
    count = gp.check_result(gp.gp_file_slurp(camera_file, file_data))
    print(count, "bytes read")
    # or read data using 'get_data_and_size' which allocates its own buffer
    ##    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    data = memoryview(file_data)
    print(type(data), len(data))
    print(data[:10].tolist())
    image = Image.open(io.BytesIO(file_data))
    image.show()
    print("After deleting camera_file and file_data")
    del camera_file, file_data
    print(type(data), len(data))
    print(data[:10].tolist())
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #12
0
    def connect(self):

        if self._camera is not None and self._context is not None:
            logging.warn('asked to connect over an opened connection, ignoring')
            return

        self.close_other_gphoto_processes()

        success = False
        tries = 1

        while not success:
            try:
                logging.debug('trying to open a connection')
                self._camera = gp.check_result(gp.gp_camera_new())
                self._context = gp.gp_context_new()
                success = True
            except Exception as ex:
                logging.debug('failed to open a connection', exc_info=True)
                if tries > 5:
                    raise ex
                tries += 1
                time.sleep(0.5)

        logging.debug('opened a new connection')
        return self
Пример #13
0
def takeApicture():
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Capturing image')
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
    curFilePath = os.path.dirname(os.path.realpath(__file__))
    imgName = "Photomat_" + datetime.now().isoformat() + ".jpg"
    target = os.path.join(curFilePath, 'static/img', imgName)
    print('Copying image to', target)
    camera_file = gp.check_result(
        gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                              gp.GP_FILE_TYPE_NORMAL))
    gp.check_result(gp.gp_file_save(camera_file, target))
    gp.check_result(gp.gp_camera_exit(camera))

    data = {"response": "OK"}

    js = json.dumps(data)
    resp = Response(js, status=200, mimetype='application/json')
    return resp
Пример #14
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Getting list of files')
    files = list_files(camera)
    if not files:
        print('No files found')
        return 1
    path = files[0]
    print('Copying %s to memory' % path)
    folder, name = os.path.split(path)
    camera_file = gp.check_result(gp.gp_camera_file_get(
        camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
##    # read file data using 'slurp' and a buffer allocated in Python
##    info = gp.check_result(
##        gp.gp_camera_file_get_info(camera, folder, name))
##    file_data = bytearray(info.file.size)
##    count = gp.check_result(gp.gp_file_slurp(camera_file, file_data))
##    print(count, 'bytes read')
    # or read data using 'get_data_and_size' which allocates its own buffer
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    data = memoryview(file_data)
    print(type(data), len(data))
    print(data[:10].tolist())
    image = Image.open(io.BytesIO(file_data))
    image.show()
    print('After deleting camera_file and file_data')
    del camera_file, file_data
    print(type(data), len(data))
    print(data[:10].tolist())
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #15
0
def take_photo():

    # Get the directory containing this script
    photoDir = os.path.dirname(os.path.realpath(__file__))

    # Create capture directory
    photoDirName = "photos"
    photoDir = os.path.join(photoDir, photoDirName)
    if not os.path.exists(photoDir):
        print("Creating photo directory")
        os.makedirs(photoDir)

    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Capturing image')
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
    photoFile = os.path.join(photoDir, file_path.name)
    print('Copying image to', photoFile)
    camera_file = gp.check_result(
        gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                              gp.GP_FILE_TYPE_NORMAL))
    gp.check_result(gp.gp_file_save(camera_file, photoFile))
    #subprocess.call(['xdg-open', photoFile])
    gp.check_result(gp.gp_camera_exit(camera))

    return photoFile
Пример #16
0
def info():
    context = gp_context_new()
    error, camera = gp_camera_new()
    error = gp_camera_init(camera, context)
    error, text = gp_camera_get_summary(camera, context)
    error = gp_camera_exit(camera, context)
    return text.text
Пример #17
0
def main():
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    files = list_files(camera, context)
    if not files:
        print('No files found')
        return 1
    print('File list')
    print('=========')
    for path in files[:10]:
        print(path)
    print('...')
    for path in files[-10:]:
        print(path)
    info = get_file_info(camera, context, files[-1])
    print
    print('File info')
    print('=========')
    print('image dimensions:', info.file.width, info.file.height)
    print('image type:', info.file.type)
    print('file mtime:',
          datetime.fromtimestamp(info.file.mtime).isoformat(' '))
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #18
0
def main():
    # use Python logging
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    # open camera connection
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the capture target config item
    capture_target = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'capturetarget'))
    # print current setting
    value = gp.check_result(gp.gp_widget_get_value(capture_target))
    print('Current setting:', value)
    # print possible settings
    for n in range(gp.check_result(
            gp.gp_widget_count_choices(capture_target))):
        choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n))
        print('Choice:', n, choice)
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #19
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    computer_files = list_computer_files()
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    print('Getting list of files from camera...')
    camera_files = list_camera_files(camera, context)
    if not camera_files:
        print('No files found')
        return 1
    print('Copying files...')
    for path in camera_files:
        info = get_camera_file_info(camera, context, path)
        timestamp = datetime.fromtimestamp(info.file.mtime)
        folder, name = os.path.split(path)
        dest_dir = get_target_dir(timestamp)
        dest = os.path.join(dest_dir, name)
        if dest in computer_files:
            continue
        print('%s -> %s' % (path, dest_dir))
        if not os.path.isdir(dest_dir):
            os.makedirs(dest_dir)
        camera_file = gp.check_result(gp.gp_file_new())
        gp.check_result(gp.gp_camera_file_get(
            camera, folder, name, gp.GP_FILE_TYPE_NORMAL, camera_file, context))
        gp.check_result(gp.gp_file_save(camera_file, dest))
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #20
0
    def __init__(self):
        print "init AstroCamCanon"

        gp.check_result(gp.use_python_logging())
        self.context = gp.gp_context_new()
        self.camera = gp.check_result(gp.gp_camera_new())
        print "config"
        camera_config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context))
        child_count = gp.check_result(gp.gp_widget_count_children(camera_config))
        
        print child_count
        for n in range(child_count):
            try:
                print "============"
                child = gp.check_result(gp.gp_widget_get_child(camera_config, n))
                name = gp.check_result(gp.gp_widget_get_name(child))
                print name
                chtype = gp.check_result(gp.gp_widget_get_type(child))
                print chtype
                ro = gp.check_result(gp.gp_widget_get_readonly(child))
                print ro
                cdildcen = gp.check_result(gp.gp_widget_count_children(child))
                print cdildcen
                

            except Exception, e:
                print e
Пример #21
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Getting list of files')
    files = list_files(camera)
    if not files:
        print('No files found')
        return 1
    path = files[0]
    print('Copying %s to memory in 100 kilobyte chunks' % path)
    folder, name = os.path.split(path)
    file_info = gp.check_result(gp.gp_camera_file_get_info(
        camera, folder, name))
    data = bytearray(file_info.file.size)
    view = memoryview(data)
    chunk_size = 100 * 1024
    offset = 0
    while offset < len(data):
        bytes_read = gp.check_result(gp.gp_camera_file_read(
            camera, folder, name, gp.GP_FILE_TYPE_NORMAL,
            offset, view[offset:offset + chunk_size]))
        offset += bytes_read
        print(bytes_read)
    print(' '.join(map(str, data[0:10])))
    image = Image.open(io.BytesIO(data))
    image.show()
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #22
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    storage_info = gp.check_result(
        gp.gp_camera_get_storageinfo(camera, context))
    if len(storage_info) > 1:
        print('Unable to handle camera with multiple storage media')
        return 1
    if len(storage_info) == 0:
        print('No storage info available')
        return 2
    si = storage_info[0]
    if not (si.fields & gp.GP_STORAGEINFO_MAXCAPACITY
            and si.fields & gp.GP_STORAGEINFO_FREESPACEKBYTES):
        print('Cannot read storage capacity')
        return 3
    print('Camera has %.1f%% free space' %
          (100.0 * float(si.freekbytes) / float(si.capacitykbytes)))
    if len(argv) < 2:
        return 4
    if len(argv) > 2:
        print('usage: %s [percent_to_clear]' % argv[0])
        return 5
    target = float(argv[1]) / 100.0
    target = int(target * float(si.capacitykbytes))
    free_space = si.freekbytes
    if free_space >= target:
        print('Sufficient free space')
        return 0
    print('Getting file list...')
    files = list_files(camera, context)
    mtime = {}
    size = {}
    for path in files:
        info = get_file_info(camera, context, path)
        mtime[path] = info.file.mtime
        size[path] = info.file.size
    files.sort(key=lambda x: mtime[x], reverse=True)
    while True:
        while files and free_space < target:
            path = files.pop()
            print('Delete', path)
            delete_file(camera, context, path)
            free_space += size[path] // 1000
        storage_info = gp.check_result(
            gp.gp_camera_get_storageinfo(camera, context))
        si = storage_info[0]
        print('Camera has %.1f%% free space' %
              (100.0 * float(si.freekbytes) / float(si.capacitykbytes)))
        free_space = si.freekbytes
        if free_space >= target:
            break
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #23
0
    def open(self):
        self.context = gp.gp_context_new()

        error, camera = gp.gp_camera_new()
        gp.check_result(error)

        if self.port is not None:
            error = gp.gp_camera_set_port_info(camera, self.port)
            gp.check_result(error)

        error = gp.gp_camera_init(camera, self.context)  
        gp.check_result(error)

        self.camera = camera

        # create image (sub-)directory
        self.image_directory = os.path.join(self.image_base_directory, "cam_" + self.get_serialnumber())
        try:
            os.makedirs(self.image_directory)
        except FileExistsError as e:
            pass

        status = self.get_exposure_status()
        if status["expprogram"] == "A":
            self.exposure_mode = self.MODE_APERTURE_PRIORITY
        elif status["expprogram"] == "M":
            self.exposure_mode = self.MODE_MANUAL
        else:
            self.exposure_mode = self.MODE_UNKNOWN

        self.state = self.STATE_CONNECTED
Пример #24
0
def camera_test():

    # initialize camera.
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))

    # test shutter speeds
    for speed_i in speed_values:
        update_exposure_settings(camera, speed=speed_i)
        time.sleep(1)
        expset = read_exposure_settings(camera)
        print('Shutter speed set to:', speed_i, ', Current settings', expset)
        assert expset['speed'] == speed_i

    # test ISO values.
    for iso_i in iso_values:
        update_exposure_settings(camera, iso=iso_i)
        time.sleep(1)
        expset = read_exposure_settings(camera)
        print('ISO set to:', iso_i, ', Current settings', expset)
        assert expset['iso'] == iso_i

    # test apertures
    for fnum_i in fnum_values_num:
        update_exposure_settings(camera, fnum=fnum_i)
        time.sleep(1)
        expset = read_exposure_settings(camera)
        print('Aperture set to:', fnum_i, ', Current settings', expset)
        assert expset['fnum'] == fnum_i

    # close camera.
    gp.check_result(gp.gp_camera_exit(camera))
    def takePhoto(self):
        return self.takePhoto2()

        logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                            level=logging.WARNING)
        self.bCameraBusy = True
        gp.check_result(gp.use_python_logging())
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_init(camera))
        print('Capturing image')
        file_path = gp.check_result(
            gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
        print('Camera file path: {0}/{1}'.format(file_path.folder,
                                                 file_path.name))
        target = os.path.join('~/tmp', file_path.name)
        target = os.path.join(CURRENT_DIR, '..', 'LightPaintings',
                              file_path.name)
        print('Copying image to', target)
        camera_file = gp.check_result(
            gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                                  gp.GP_FILE_TYPE_NORMAL))
        gp.check_result(gp.gp_file_save(camera_file, target))
        if (self.completeRepeats == self.iRepeats):
            subprocess.call(['xdg-open', target])
        gp.check_result(gp.gp_camera_exit(camera))
        self.bCameraBusy = False
        return 0
Пример #26
0
def initCamera():
    global camera
    global context
    print("Init camera")
    # SLR Setup
    # GPhoto init / testing
    context = gp.gp_context_new()
    error, camera = gp.gp_camera_new()
    error = gp.gp_camera_init(camera, context)
    error, text = gp.gp_camera_get_summary(camera, context)
    #print('Summary')
    #print('=======')
    #print(text.text)

    # required configuration will depend on camera type!
    print('Checking camera config')
    config = gp.check_result(gp.gp_camera_get_config(camera))
    OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
    if OK >= gp.GP_OK:
        value = gp.check_result(gp.gp_widget_get_value(image_format))
        if 'raw' in value.lower():
            print('Cannot preview raw images')
    # find the capture size class config item
    OK, capture_size_class = gp.gp_widget_get_child_by_name(
        config, 'capturesizeclass')
    if OK >= gp.GP_OK:
        value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2))
        gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
        gp.check_result(gp.gp_camera_set_config(camera, config))
Пример #27
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    print('Getting list of files')
    files = list_files(camera, context)
    if not files:
        print('No files found')
        return 1
    path = files[0]
    print('Copying %s to memory in 100 kilobyte chunks' % path)
    folder, name = os.path.split(path)
    file_info = gp.check_result(gp.gp_camera_file_get_info(
        camera, folder, name, context))
    data = bytearray(file_info.file.size)
    view = memoryview(data)
    chunk_size = 100 * 1024
    offset = 0
    while offset < len(data):
        bytes_read = gp.check_result(gp.gp_camera_file_read(
            camera, folder, name, gp.GP_FILE_TYPE_NORMAL,
            offset, view[offset:offset + chunk_size], context))
        offset += bytes_read
        print(bytes_read)
    print(' '.join(map(str, data[0:10])))
    image = Image.open(io.BytesIO(data))
    image.show()
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #28
0
    def take_photo(self):
        print('Capturing image')

        self.use_cached = True

        gp.check_result(gp.gp_camera_exit(self.camera))
        self.camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_init(self.camera))

        file_path = gp.check_result(
            gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE))

        info = gp.check_result(
            gp.gp_camera_file_get_info(self.camera, file_path.folder,
                                       file_path.name))
        timestamp = info.file.mtime
        timestamp_str = 't' + str(timestamp)
        file_name_split = file_path.name.split('.')
        file_name_split.insert(1, timestamp_str)
        file_name = '.'.join(file_name_split)
        target = os.path.join(self.PHOTO_DIR, file_name)
        if not os.path.isdir(self.PHOTO_DIR):
            os.makedirs(self.PHOTO_DIR)
        camera_file = gp.check_result(
            gp.gp_camera_file_get(self.camera, file_path.folder,
                                  file_path.name, gp.GP_FILE_TYPE_NORMAL))
        gp.check_result(gp.gp_file_save(camera_file, target))
        send_file(target)

        self.use_cached = False
Пример #29
0
def connect_camera():
  global CAMERA

  logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
  gp.check_result(gp.use_python_logging())
  CAMERA = gp.check_result(gp.gp_camera_new())
  gp.check_result(gp.gp_camera_init(CAMERA))

  # required configuration will depend on camera type!
  print "Checking camera config"
  # get configuration tree
  config = gp.check_result(gp.gp_camera_get_config(CAMERA))
  # find the image format config item
  OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
  if OK >= gp.GP_OK:
      # get current setting
      value = gp.check_result(gp.gp_widget_get_value(image_format))
      # make sure it's not raw
      if 'raw' in value.lower():
          raise PeripheralStatusError('Camera is setup to record raw, but we need previs, and preview does not work with raw images')
  # find the capture size class config item
  # need to set this on my Canon 350d to get preview to work at all
  OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass')
  if OK >= gp.GP_OK:
      # set value
      value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2))
      gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
      # set config
      gp.check_result(gp.gp_camera_set_config(CAMERA, config))
Пример #30
0
    def takePhoto(self):

        context = gp.gp_context_new()
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_init(camera, context))

        print("Capturing image")

        file_path = gp.check_result(gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))

        print("Camera file path: {0}/{1}".format(file_path.folder, file_path.name))

        target = os.path.join("/tmp", file_path.name)

        print("Copying image to", target)

        camera_file = gp.check_result(
            gp.gp_camera_file_get(camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)
        )

        gp.check_result(gp.gp_file_save(camera_file, target))

        gp.check_result(gp.gp_camera_exit(camera, context))

        return target
Пример #31
0
def open_camera():
    """ context manager to control access to the camera resource """
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    yield camera, context
    gp.check_result(gp.gp_camera_exit(camera, context))
Пример #32
0
 def change_iso_setting(self):
     camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(camera))
     camera_config = gp.check_result(gp.gp_camera_get_config(camera))
     for child in gp.check_result(gp.gp_widget_get_children(camera_config)):
         print(gp.check_result(gp.gp_widget_get_label(child)))
     gp.check_result(gp.gp_camera_exit(camera))
Пример #33
0
 def init_camera(self):
     self.log.debug("Init GPhoto2 camera")
     callback_obj = gp.check_result(gp.use_python_logging())
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     # required configuration will depend on camera type!
     self.log.info('Checking camera config')
     # get configuration tree
     config = gp.check_result(gp.gp_camera_get_config(self.camera))
     # find the image format config item
     OK, image_format = gp.gp_widget_get_child_by_name(
         config, 'imageformat')
     if OK >= gp.GP_OK:
         # get current setting
         value = gp.check_result(gp.gp_widget_get_value(image_format))
         # make sure it's not raw
         if 'raw' in value.lower():
             self.log.error('Cannot preview raw images')
             return None
     # find the capture size class config item
     # need to set this on my Canon 350d to get preview to work at all
     OK, capture_size_class = gp.gp_widget_get_child_by_name(
         config, 'capturesizeclass')
     if OK >= gp.GP_OK:
         # set value
         value = gp.check_result(
             gp.gp_widget_get_choice(capture_size_class, 2))
         gp.check_result(gp.gp_widget_set_value(capture_size_class, value))
         # set config
         gp.check_result(gp.gp_camera_set_config(self.camera, config))
     return True
Пример #34
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    print('Getting list of files')
    files = list_files(camera, context)
    if not files:
        print('No files found')
        return 1
    path = files[0]
    print('Copying %s to memory' % path)
    folder, name = os.path.split(path)
    camera_file = gp.check_result(gp.gp_camera_file_get(
        camera, folder, name, gp.GP_FILE_TYPE_NORMAL, context))
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
    data = memoryview(file_data)
    print(type(data), len(data))
    print(data[:10].tolist())
    image = Image.open(io.BytesIO(file_data))
    image.show()
    print('After deleting camera_file and file_data')
    del camera_file, file_data
    print(type(data), len(data))
    print(data[:10].tolist())
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
def main():
    # use Python logging
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    # get user value
    if len(sys.argv) != 2:
        print('One command line parameter required')
        return 1
    try:
        value = int(sys.argv[1])
    except:
        print('Integer parameter required')
        return 1
    # open camera connection
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera))
    # find the capture target config item
    capture_target = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'capturetarget'))
    # check value in range
    count = gp.check_result(gp.gp_widget_count_choices(capture_target))
    if value < 0 or value >= count:
        print('Parameter out of range')
        return 1
    # set value
    value = gp.check_result(gp.gp_widget_get_choice(capture_target, value))
    gp.check_result(gp.gp_widget_set_value(capture_target, value))
    # set config
    gp.check_result(gp.gp_camera_set_config(camera, config))
    # clean up
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #36
0
def capture(save_path, filename):
    #log to be used by gphoto
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    context = gp.gp_context_new()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))

    config = camera.get_config(context)
    target = config.get_child_by_name('viewfinder')
    target.set_value(1)
    camera.set_config(config, context)
    target.set_value(0)
    camera.set_config(config, context)

    time.sleep(2)

    #capture the image (to camera's internal SD card)
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE))

    #Copy the image over usb to the local filesystem
    target = os.path.join(save_path, filename)
    camera_file = gp.check_result(gp.gp_camera_file_get(
            camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL))

    gp.gp_file_save(camera_file, target)

    #exit the camera to complete the process
    gp.gp_camera_exit(camera)
    return 0
Пример #37
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    files = list_files(camera)
    if not files:
        print('No files found')
        return 1
    print('File list')
    print('=========')
    for path in files[:10]:
        print(path)
    print('...')
    for path in files[-10:]:
        print(path)
    info = get_file_info(camera, files[-1])
    print
    print('File info')
    print('=========')
    print('image dimensions:', info.file.width, info.file.height)
    print('image type:', info.file.type)
    print('file mtime:', datetime.fromtimestamp(info.file.mtime).isoformat(' '))
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
Пример #38
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    storage_info = gp.check_result(gp.gp_camera_get_storageinfo(camera, context))
    if len(storage_info) > 1:
        print('Unable to handle camera with multiple storage media')
        return 1
    if len(storage_info) == 0:
        print('No storage info available')
        return 2
    si = storage_info[0]
    if not (si.fields & gp.GP_STORAGEINFO_MAXCAPACITY and
            si.fields & gp.GP_STORAGEINFO_FREESPACEKBYTES):
        print('Cannot read storage capacity')
        return 3
    print('Camera has %.1f%% free space' % (
        100.0 * float(si.freekbytes) / float(si.capacitykbytes)))
    if len(argv) < 2:
        return 4
    if len(argv) > 2:
        print('usage: %s [percent_to_clear]' % argv[0])
        return 5
    target = float(argv[1]) / 100.0
    target = int(target * float(si.capacitykbytes))
    free_space = si.freekbytes
    if free_space >= target:
        print('Sufficient free space')
        return 0
    print('Getting file list...')
    files = list_files(camera, context)
    mtime = {}
    size = {}
    for path in files:
        info = get_file_info(camera, context, path)
        mtime[path] = info.file.mtime
        size[path] = info.file.size
    files.sort(key=lambda x: mtime[x], reverse=True)
    while True:
        while files and free_space < target:
            path = files.pop()
            print('Delete', path)
            delete_file(camera, context, path)
            free_space += size[path] // 1000
        storage_info = gp.check_result(
            gp.gp_camera_get_storageinfo(camera, context))
        si = storage_info[0]
        print('Camera has %.1f%% free space' % (
            100.0 * float(si.freekbytes) / float(si.capacitykbytes)))
        free_space = si.freekbytes
        if free_space >= target:
            break
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #39
0
def init_camera() -> gp.camera:
    """initialize the camera"""
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    return camera
Пример #40
0
def initCam():
	global context, camera
	logging.basicConfig(
		format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
	gp.check_result(gp.use_python_logging())
	context = gp.gp_context_new()
	camera = gp.check_result(gp.gp_camera_new())
	gp.check_result(gp.gp_camera_init(camera, context))
Пример #41
0
    def __init__(self, model=None):
        self.model = model

        if self.model == "canonEOS":
            gp.check_result(gp.use_python_logging())
            self.context = gp.gp_context_new()
            self.camera = gp.check_result(gp.gp_camera_new())
            gp.check_result(gp.gp_camera_init(self.camera, self.context))
Пример #42
0
def initCam():
    global context, camera
    logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                        level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    context = gp.gp_context_new()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera, context))
Пример #43
0
 def initialise(self):
     # get camera config tree
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     self.camera_config = gp.check_result(
         gp.gp_camera_get_config(self.camera))
     # create corresponding tree of tab widgets
     self.setWindowTitle(
         gp.check_result(gp.gp_widget_get_label(self.camera_config)))
     self.centralWidget().layout().addWidget(
         SectionWidget(self.config_changed, self.camera_config), 0, 0, 1, 3)
Пример #44
0
 def __init__(self):
     self.PHOTO_DIR = os.path.expanduser(
         '~/Documents/photobooth/backend-server/photos')
     self.file_cache = None
     logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
                         level=logging.WARNING)
     gp.check_result(gp.use_python_logging())
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     gp.check_result(gp.gp_camera_capture_preview(self.camera))
     self.use_cached = False
Пример #45
0
 def rgb_camera_connection_service_cb(self, req):
     if not hasattr(self, 'rgb_camera'):
         try:
             gp.check_result(gp.use_python_logging())
             self.rgb_camera = gp.check_result(gp.gp_camera_new())
             gp.check_result(gp.gp_camera_init(self.rgb_camera))
             rospy.loginfo('PAL: init RGB Camera')
             return True
         except:
             rospy.logerr("PAL: RGB camera connection failed")
             return False
Пример #46
0
 def initialise(self):
     # get camera config tree
     self.camera = gp.check_result(gp.gp_camera_new())
     self.context = gp.gp_context_new()
     gp.check_result(gp.gp_camera_init(self.camera, self.context))
     self.camera_config = gp.check_result(
         gp.gp_camera_get_config(self.camera, self.context))
     # create corresponding tree of tab widgets
     self.setWindowTitle(
         gp.check_result(gp.gp_widget_get_label(self.camera_config)))
     self.centralWidget().layout().addWidget(SectionWidget(
         self.config_changed, self.camera_config), 0, 0, 1, 3)
Пример #47
0
def setup():
    """
    Attempt to attach to a gphoto device and grab the camera and context. Return the results.
    """
    logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    context = gp.gp_context_new()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera, context))
    text = gp.check_result(gp.gp_camera_get_summary(camera, context))
    print text.text
    return camera, context
def main():
        logging.basicConfig(
                format='%(levelname)s: %(name)s: %(message)s', level=logging.CRITICAL)
        gp.check_result(gp.use_python_logging())
        camera = gp.check_result(gp.gp_camera_new())
        context = gp.gp_context_new()
        gp.check_result(gp.gp_camera_init(camera, context))

        trigger_capture(camera, context, 'image.jpg')

        gp.check_result(gp.gp_camera_exit(camera, context))
        return 0
Пример #49
0
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    context = gp.gp_context_new()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera, context))
    text = gp.check_result(gp.gp_camera_get_summary(camera, context))
    print('Summary')
    print('=======')
    print(text.text)
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
 def initialise(self):
     # get camera config tree
     self.camera = gp.check_result(gp.gp_camera_new())
     gp.check_result(gp.gp_camera_init(self.camera))
     self.camera_config = gp.check_result(
         gp.gp_camera_get_config(self.camera))
     # create corresponding tree of tab widgets
     self.setWindowTitle(
         gp.check_result(gp.gp_widget_get_label(self.camera_config)))
     top_widget = SectionWidget(self.config_changed, self.camera_config)
     scroll_area = QtWidgets.QScrollArea()
     scroll_area.setWidget(top_widget)
     scroll_area.setWidgetResizable(True)
     self.centralWidget().layout().addWidget(scroll_area, 0, 0, 1, 3)
Пример #51
0
    def open_camera(self):
        # the following needs to be changed into some
        # kind of context manager aware delay to allow
        # the camera to get ready in a context manager
        release_from_tight_grip_of_operating_system()

        ctx = gp.gp_context_new()
        error, camera = gp.gp_camera_new()
        gp.check_result(gp.gp_camera_init(camera, ctx))

        # TODO: check if camera cannot be used for some reason

        self._camera = camera
        self._context = ctx
Пример #52
0
def main():
    # use Python logging
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    # open camera connection
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the date/time setting config item and get it
    # name varies with camera driver
    #   Canon EOS350d - 'datetime'
    #   PTP - 'd034'
    for name, fmt in (('datetime', '%Y-%m-%d %H:%M:%S'),
                      ('d034',     None)):
        now = datetime.now()
        OK, datetime_config = gp.gp_widget_get_child_by_name(config, name)
        if OK >= gp.GP_OK:
            widget_type = gp.check_result(gp.gp_widget_get_type(datetime_config))
            if widget_type == gp.GP_WIDGET_DATE:
                raw_value = gp.check_result(
                    gp.gp_widget_get_value(datetime_config))
                camera_time = datetime.fromtimestamp(raw_value)
            else:
                raw_value = gp.check_result(
                    gp.gp_widget_get_value(datetime_config))
                if fmt:
                    camera_time = datetime.strptime(raw_value, fmt)
                else:
                    camera_time = datetime.utcfromtimestamp(float(raw_value))
            print('Camera clock:  ', camera_time.isoformat(' '))
            print('Computer clock:', now.isoformat(' '))
            err = now - camera_time
            if err.days < 0:
                err = -err
                lead_lag = 'ahead'
                print('Camera clock is ahead by',)
            else:
                lead_lag = 'behind'
            print('Camera clock is %s by %d days and %d seconds' % (
                lead_lag, err.days, err.seconds))
            break
    else:
        print('Unknown date/time config item')
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0
Пример #53
0
 def __init_camera(self):
     error, self.__camera = gp.gp_camera_new()
     self.__context = gp.gp_context_new()
     error = gp.gp_camera_init(self.__camera, self.__context)
     error, text = gp.gp_camera_get_summary(self.__camera, self.__context)
     #print('Summary')
     #('=======')
     #print(text.text)
     self.__config = gp.check_result(gp.gp_camera_get_config(self.__camera, self.__context))
     self.__config_dict = OrderedDict()
     self.__walk_config(self.__config,self.__config_dict)
     self.print_settings()
     self.__watcher = QtCore.QFileSystemWatcher([self.__cfg_file_path], self)
     self.__watcher.fileChanged.connect(self.load_settings)
     self.load_settings(self.__cfg_file_path)
Пример #54
0
 def __init__(self, name = "My Camera", camera = None, context = None,
         controlfocus = False):
     self.name = name
     if context is None:
         self.context = gp.gp_context_new()
     else:
         self.context = context
     if camera is None:
         self.camera = gp.check_result(gp.gp_camera_new());
     else:
         self.camera = camera
     self.logger = logging.getLogger(self.name)
     self.controlfocus = controlfocus
     self.in_preview = False
     gp.check_result(gp.gp_camera_init(self.camera, self.context))
    def __init__(self):
        """
        Initialise the camera
        :return:
        """
        try:
            self.camera = gp.check_result(gp.gp_camera_new())
            self.context = gp.gp_context_new()
            self.path_root = '/camera/imgCap/'
            self.path_single = '/camera/imgCap/single/'
            self.path_hdr3 = '/camera/imgCap/hdr3/'
            self.path_hdr5 = '/camera/imgCap/hdr5/'

        except Exception as e:
            logger.error(e.message)
Пример #56
0
    def connect(self):
        self.context = gp.gp_context_new()
        print self.context
        self.camera = gp.check_result(gp.gp_camera_new())
        print self.camera
        gp.check_result(gp.gp_camera_init(self.camera, self.context))
        text = gp.check_result(gp.gp_camera_get_summary(self.camera, self.context))
        print('Summary')
        print('=======')
        print(text.text)
        
        print('Abilities')
        print('=========')
        abilities = gp.check_result(gp.gp_camera_get_abilities(self.camera))
        print('model:', abilities.model)
        print('status:', abilities.status)
        print('port:', abilities.port)
        print('speed:', abilities.speed)
        print('operations:', abilities.operations)
        print('file_operations:', abilities.file_operations)
        print('folder_operations:', abilities.folder_operations)
        print('usb_vendor:', abilities.usb_vendor)
        print('usb_product:', abilities.usb_product)
        print('usb_class:', abilities.usb_class)
        print('usb_subclass:', abilities.usb_subclass)
        print('usb_protocol:', abilities.usb_protocol)
        print('library:', abilities.library)
        print('id:', abilities.id)
        print('device_type:', abilities.device_type)
        print "--------------"
        print abilities
        

        rospy.set_param('AROM_camera/%s/model' %(self.name), abilities.model)
        rospy.set_param('AROM_camera/%s/config' %(self.name),
            {'name': self.arg['name'],
             'civil_name': self.arg['civil_name'],
             'driver': self.arg['driver'],
             'model': abilities.model,
             '#main':{
                        '@capture': {'type': 'button', 'msg_name': 'capture'},
                        '@Shutter_speed': {'type': 'select', 'msg_name': 'shutter_speed', 'value': {'0': "1/4000", '1': "1/1000", '2': "1/800"}},
                        '@ISO': {'type': 'select', 'msg_name': 'gain', 'value': {'0': "AUTO", '1': "100", '2': "200"}},
                        '@ISO': {'type': 'select', 'msg_name': 'gain', 'value': {'0': "AUTO", '1': "100", '2': "200"}}
                    }
            }
        )
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Capturing image')
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE))
    print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
    target = os.path.join('/tmp', file_path.name)
    print('Copying image to', target)
    camera_file = gp.check_result(gp.gp_camera_file_get(
            camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL))
    gp.check_result(gp.gp_file_save(camera_file, target))
    subprocess.call(['xdg-open', target])
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
def main():
    # Init camera
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    timeout = 3000 # miliseconds
    while True:
        event_type, event_data = gp.check_result(
            gp.gp_camera_wait_for_event(camera, timeout))
        if event_type == gp.GP_EVENT_FILE_ADDED:
            # Get the image from the camera
            camera_file = gp.check_result(gp.gp_camera_file_get(
                camera, event_data.folder, event_data.name,
                gp.GP_FILE_TYPE_NORMAL))
            # Path where the image is to be saved
            target_path= os.path.join(os.getcwd(), event_data.name)
            print("Picture is saved to {}".format(target_path))
            gp.check_result(gp.gp_file_save(camera_file, target_path))
    return 0
Пример #59
0
def capture(downloadPath, resultFile, showImage):
    context = gp.gp_context_new()
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera, context))
    print('Capturing image')
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE, context))
    print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
    target = downloadPath+"/"+resultFile
    print('Copying image to', target)
    camera_file = gp.check_result(gp.gp_camera_file_get(            
        camera, file_path.folder, file_path.name,
        gp.GP_FILE_TYPE_NORMAL, context))
    gp.check_result(gp.gp_file_save(camera_file, target))
    if (showImage):
        subprocess.call(['xdg-open', target])
    gp.check_result(gp.gp_camera_exit(camera, context))
    return True
def main():
    # use Python logging
    logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.WARNING)
    gp.check_result(gp.use_python_logging())
    # open camera connection
    camera = gp.check_result(gp.gp_camera_new())
    context = gp.gp_context_new()
    gp.check_result(gp.gp_camera_init(camera, context))
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the date/time setting config item and set it
    if set_datetime(config):
        # apply the changed config
        gp.check_result(gp.gp_camera_set_config(camera, config, context))
    else:
        print("Could not set date & time")
    # clean up
    gp.check_result(gp.gp_camera_exit(camera, context))
    return 0