예제 #1
0
파일: zerobox.py 프로젝트: volzotan/timebox
    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
예제 #2
0
파일: __init__.py 프로젝트: jdemaeyer/ice
def get_all_cameras():
    # Ugh, C libraries >.<
    # Get all available ports
    portinfolist = gp.check_result(gp.gp_port_info_list_new())
    gp.check_result(gp.gp_port_info_list_load(portinfolist))
    # Get all available cameras and a string of their port
    context = gp.gp_context_new()
    camlist = gp.check_result(gp.gp_camera_autodetect(context))
    cameralist = []
    for i in range(camlist.count()):
        camname = camlist.get_name(i)
        camport = camlist.get_value(i)
        # Find port info for this camera
        portindex = portinfolist.lookup_path(camport)
        portinfo = portinfolist.get_info(portindex)
        # Create camera object and associate with given port
        cam = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_set_port_info(cam, portinfo))
        myCamera = Camera("{} ({})".format(camname, camport), cam, context)
        cameralist.append(myCamera)
    return cameralist
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_list = gp.check_result(gp.gp_camera_autodetect(context))
#    gp.check_result(gp.gp_camera_init(camera, context))
    
#    camera_list = GetCameraList(context)


    # loop through camera list
    for index, (name, addr) in enumerate(camera_list):
        print('Processing camera {:d}:  {:s}  {:s}'.format(index, addr, name))

    # search ports for camera port name and match to this iteration
        port_info_list = gp.check_result(gp.gp_port_info_list_new())
        gp.check_result(gp.gp_port_info_list_load(port_info_list))
        idx = gp.check_result(gp.gp_port_info_list_lookup_path(port_info_list, addr))

    # open this camera and associated context
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_set_port_info(camera,port_info_list[idx]))
        gp.check_result(gp.gp_camera_init(camera,context))

    # get camera configuration
        config = gp.check_result(gp.gp_camera_get_config(camera,context))

    # grab current value of imageformat and change to JPG
        image_format_old = get_config_value(config,'imageformat')
        set_config_value(camera,config,context,'imageformat',jpgFormat)
        image_format = get_config_value(config,'imageformat')

        print('Changed image format from {:s} to {:s}'.format(image_format_old,image_format))

    # close this camera
        gp.check_result(gp.gp_camera_exit(camera,context))
        
    return 0