Пример #1
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
def trigger_capture(camera, context, dstpath='image.jpg'):
	""" Trigger capture must be used instead of capture if you want to shoot while the mirror is locked up
	and you do not want to re-focus - set capture format on camera"""
        timeout = 20
        starttime = time.time()

        gp.check_result(gp.gp_camera_trigger_capture(camera, context))
        filefound = [False, False]

        while filefound[1] != gp.GP_EVENT_FILE_ADDED:
                filefound = gp.gp_camera_wait_for_event(camera, 10000, context)
                if time.time() - starttime > timeout:
                        print ('operation timed out')
                        return False
	
	campath = '/'
        filelist = list_files(camera, context, campath)

        for f in filelist:
                filename = f.strip(campath)
                camfile = gp.check_result(gp.gp_file_new())
                gp.gp_camera_file_get(camera, campath, filename, gp.GP_FILE_TYPE_NORMAL, camfile, context)
                gp.gp_file_save(camfile, dstpath)
                gp.gp_file_unref(camfile)
                gp.gp_camera_file_delete(camera, campath, filename, context)
                
        endtime = round(time.time() - starttime, 2)
        print ('capture complete in {}s'.format(endtime))	        
Пример #3
0
def capture_frame(camera, context):
    error, file = gp.gp_camera_capture_preview(camera, context)
    if error != 0:
        print(gp.gp_result_as_string(error))
    gp.gp_file_save(file, "photo.jpg")
    photo = cv2.imread("photo.jpg")
    return photo
Пример #4
0
def capture_and_save():
    print("Capturing")
    file_path = camera.capture(gp.GP_CAPTURE_IMAGE)
    fd = camera.file_get(file_path.folder, file_path.name,
                         gp.GP_FILE_TYPE_NORMAL)
    target = os.path.join(scandir, file_path.name)
    gp.gp_file_save(fd, target)
    camera.exit()
    print("Saved file " + target)
Пример #5
0
 def __capture_to_file(self):
     """Capture an image."""
     self.__restart()
     img = self.cam.capture(gp.GP_CAPTURE_IMAGE, self.ctx)
     filename = img.name
     filepath = img.folder
     file = self.cam.file_get(filepath, filename, gp.GP_FILE_TYPE_NORMAL)
     filename = os.path.join(self.capture_directory,
                             self.filename_formatter.filename(filename))
     gp.gp_file_save(file, filename)
     return filename
Пример #6
0
def captureImage():
    updateWeb()
    context = gp.Context()
    gp.Camera()
    C = gp.Camera()

    filename = 'Photoboothphoto_' + str(curTime()) + '.jpg'
    cap = C.capture(gp.GP_CAPTURE_IMAGE, context)
    print("Captured " + cap.folder + "/" + cap.name)
    file = C.file_get(cap.folder, cap.name, gp.GP_FILE_TYPE_NORMAL)
    gp.gp_file_save(file, filename)
    return filename
def main():

    # Init camera
    camera = gp.Camera()
    camera.init()
    timeout = 3000  # miliseconds
    while (True):
        result, img = camera.wait_for_event(timeout)
        if (result == gp.GP_EVENT_FILE_ADDED):
            _, cam_file = gp.gp_camera_file_get(camera, img.folder, img.name,
                                                gp.GP_FILE_TYPE_NORMAL)
            target_path = os.path.join(os.getcwd(), img.name)
            print("Image is being saved to {}".format(target_path))
            gp.gp_file_save(cam_file, target_path)
    return 0
Пример #8
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
Пример #9
0
def one_photo(camera, context, value, filename):
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the capture target config item
    shutterspeed = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'shutterspeed'))
    # check value in range
    count = gp.check_result(gp.gp_widget_count_choices(shutterspeed))
    if value < 0 or value >= count:
        print('Parameter out of range')
        return 1
    # set value
    speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value))

    gp.check_result(
        gp.gp_widget_set_value(shutterspeed, speedvalue)
    )  # set config gp.check_result(gp.gp_camera_set_config(camera, config, context))
    print('Capturing image (shutterspeed=%d)' % value)
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))

    target = filename + ".jpg"

    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))
Пример #10
0
    def _get_file(self,
                  dir_name: str,
                  file_name: str,
                  dest_full_filename: Optional[str] = None,
                  file_type: int = gp.GP_FILE_TYPE_NORMAL) -> gp.CameraFile:

        try:
            camera_file = gp.check_result(
                gp.gp_camera_file_get(self.camera, dir_name, file_name,
                                      file_type, self.context))
        except gp.GPhoto2Error as ex:
            logging.error('Error reading %s from camera %s: %s',
                          os.path.join(dir_name, file_name), self.display_name,
                          gphoto2_named_error(ex.code))
            raise CameraProblemEx(code=CameraErrorCode.read, gp_exception=ex)

        if dest_full_filename is not None:
            try:
                gp.check_result(
                    gp.gp_file_save(camera_file, dest_full_filename))
            except gp.GPhoto2Error as ex:
                logging.error('Error saving %s from camera %s: %s',
                              os.path.join(dir_name, file_name),
                              self.display_name, gphoto2_named_error(ex.code))
                raise CameraProblemEx(code=CameraErrorCode.write,
                                      gp_exception=ex)

        return camera_file
Пример #11
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
Пример #12
0
    def mavlink_packet(self, m):
        '''handle mavlink packets'''
        if m.get_type() == 'GLOBAL_POSITION_INT':
            if self.settings.target_system == 0 or self.settings.target_system == m.get_srcSystem():
                self.packets_mytarget += 1
            else:
                self.packets_othertarget += 1
	    (self.vehicleLat, self.vehicleLon, self.vehicleHdg, self.vehicleAMSL) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01, m.alt*0.001)
	#if mtype == "ATTITUDE":
	    (self.vehicleRoll, self.vehiclePitch, self.vehicleYaw) = (math.degrees(m.roll), math.degrees(m.pitch), math.degrees(m.yaw))
	if m.get_type() == "CAMERA_STATUS":
		print ("Got Message camera_status")
	if m.get_type() == "CAMERA_FEEDBACK":
		print ("Got Message camera_feedback")
		'''self.__vCmdCamTrigger(m)'''	
		file_path = gp.check_result(gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE, self.context))

		geotagFile = open(self.imageLogFilePath, 'a')
		params = "%s\t%f\t%f\t%f\t%f\t%f\t%f\n" % (file_path.name, self.vehicleLat, self.vehicleLon, self.vehicleAMSL, self.vehicleRoll, self.vehiclePitch, self.vehicleYaw)
		geotagFile.write(params)
		geotagFile.close()
		print(params)
    		print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
		target = os.path.join(self.targetPath, file_path.name)
		print('Copying image to', target)
		camera_file = gp.check_result(gp.gp_camera_file_get(self.camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, self.context))
		gp.check_result(gp.gp_file_save(camera_file, target))
		gp.check_result(gp.gp_camera_exit(camera, self.context))
		
	if m.get_type() == "COMMAND_LONG":
		if m.command == mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONFIGURE:
			print ("Got Message Digicam_configure")
		elif m.command == mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONTROL:
			print ("Got Message Digicam_control")
Пример #13
0
def getPicture(camera, context):
    print('Capturing image')
    showCapture(getClockFile(), (400, 400))
    pygame.display.flip()
    current = os.path.join(TMPPATH, getImageName())
    if os.path.exists(current):
        os.unlink(current)
    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))
    if not os.path.exists(TMPPATH):
        os.makedirs(TMPPATH)
    target = os.path.join(TMPPATH, getImageName(False))
    print('Copying image to', target)
    try:
        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))
    except:
        pass
    rt = gp.gp_camera_file_delete(camera, file_path.folder, file_path.name,
                                  context)
    showCapture(target)
    return target
Пример #14
0
    def capture_image(self, method):
        """
        Capture image
        :param method:
        :return:
        """

        try:
            file_path = gp.check_result(
                gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE,
                                     self.context))
            if method == 'single':
                path = self.path_single

            elif method == 'hdr3':
                path = self.path_hdr3

            elif method == 'hdr5':
                path = self.path_hdr5

            target = os.path.join(path, file_path.name)
            camera_file = gp.check_result(
                gp.gp_camera_file_get(self.camera, file_path.folder,
                                      file_path.name, gp.GP_FILE_TYPE_NORMAL,
                                      self.context))
            gp.check_result(gp.gp_file_save(camera_file, target))
            # Count shutter count from image
            count = self.get_image_shutter(path + file_path.name)
            update_camera(str(count))

        except Exception as e:
            logger.error(e.message)
Пример #15
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)})
Пример #16
0
    def take_picture(self, path, name):
        """ Take a picture with the camera """

        # Ensure directory exists or create it
        if (not os.path.exists(path)) or (not os.path.isdir(path)):
            log.debug("Creating the directory : " + path)
            os.makedirs(path)

        # TODO To review...

        print('Capturing image')
        try:
            file_path = gp.check_result(
                gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE,
                                     self.context))
        except Exception as err:
            print('Exception %s', err)
            return
        print('After the exception')
        camera_file = gp.check_result(
            gp.gp_camera_file_get(self.camera, file_path.folder,
                                  file_path.name, gp.GP_FILE_TYPE_NORMAL,
                                  self.context))  # TODO define context ??
        target = os.path.join(path, name)
        gp.check_result(gp.gp_file_save(camera_file, target))
        return target
Пример #17
0
def capture_image():
    # 拍照
    file_path = gp.check_result(gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    # 存照片路径
    global imgPath

    target = os.path.join('imgs', file_path.name)
    imgPath = target
    print(imgPath, file_path.folder, file_path.name)
    # 相机文件
    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))
    capture_and_resize_image()

    # 用SOCKET将照片传回服务器(本地或云)
    print('transmite image')
    TransmitImage(PHOTO_PATH) #PHOTO_PATH:修剪过后的照片名字

    # 获取二维码后显示到屏幕一段时间,让用户拿出手机扫吗
    # scanQRCode('qrcode.jpg')

    # 删除照片
    remove_file(target)     # remove captured file
    remove_file(PHOTO_PATH) # remove resized file
Пример #18
0
def capture(camera, context, dstpath='image.jpg'):
        """ Capture an image - verify file capture format on camera before setting dstpath """
        camfile = gp.check_result(gp.gp_file_new())
        campath = gp.CameraFilePath()
        
        starttime = time.time()

        gp.check_result(gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, campath, context))
        
        gp.gp_camera_file_get(camera, campath.folder, campath.name, gp.GP_FILE_TYPE_NORMAL, camfile, context)
        gp.gp_file_save(camfile, dstpath)
        gp.gp_file_unref(camfile)
        gp.check_result(gp.gp_camera_file_delete(camera, campath.folder, campath.name, context))

        endtime = round(time.time() - starttime, 2)
        print ('capture complete in {}s'.format(endtime))	        
def one_photo(camera, context, value, filename):
    # get configuration tree
    config = gp.check_result(gp.gp_camera_get_config(camera, context))
    # find the capture target config item
    shutterspeed = gp.check_result(
        gp.gp_widget_get_child_by_name(config, 'shutterspeed'))
    # check value in range
    count = gp.check_result(gp.gp_widget_count_choices(shutterspeed))
    if value < 0 or value >= count:
        print('Parameter out of range')
        return 1
    # set value
    speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value))

    gp.check_result(gp.gp_widget_set_value(shutterspeed, speedvalue)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context))
    print('Capturing image (shutterspeed=%d)' % value)
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE, context))

    target = filename+".jpg"

    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))
Пример #20
0
def takePhoto(camera, pictureFolder):
    #global camera

    logging.info('Capturing image...')
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    logging.debug('Picture path on the camera : {0}/{1}'.format(
        file_path.folder, file_path.name))
    # Get the name of the picture just taken
    pictureFile = gp.check_result(
        gp.gp_camera_file_get(camera, file_path.folder, file_path.name,
                              gp.GP_FILE_TYPE_NORMAL))

    # Build a timestamp to name the picture
    now = time.time()
    timestamp = datetime.datetime.fromtimestamp(now).strftime(
        '%Y-%m-%d_%H-%M-%S')
    extension = '.jpg'
    newPictureFile = os.path.join(pictureFolder, timestamp + extension)

    # Save the picture to the indicated folder
    gp.check_result(gp.gp_file_save(pictureFile, newPictureFile))
    logging.info('New picture : %s' % newPictureFile)

    return timestamp + extension
Пример #21
0
def timelapse(frames, inter):
    # Params
    frames = frames
    inter = inter

    # Open Camera
    context = gp.Context()
    camera = gp.Camera()
    camera.init(context)

    # Capture Image
    for i in range(0, frames):
        print i
        file_path = gp.check_result(camera.capture(gp.GP_CAPTURE_IMAGE, context))
        print ("Camera file path: " + file_path.folder + file_path.name)
        target = os.path.join("/home/pi/timelapse/", file_path.name + str(i))
        camera_file = gp.check_result(
            camera.file_get(file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)
        )
        gp.check_result(gp.gp_file_save(camera_file, target))

        # Show the Image
        sub = subprocess.Popen(["fim", target], preexec_fn=os.setsid)
        time.sleep(10)
        os.killpg(sub.pid, signal.SIGTERM)
        time.sleep(inter - 10)

        # Exit session
    camera.exit(context)
    def capture_image(self, method):
        """
        Capture image
        :param method:
        :return:
        """

        try:
            file_path = gp.check_result(gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE, self.context))
            if method == 'single':
                path = self.path_single

            elif method == 'hdr3':
                path = self.path_hdr3

            elif method == 'hdr5':
                path = self.path_hdr5

            target = os.path.join(path, file_path.name)
            camera_file = gp.check_result(gp.gp_camera_file_get(self.camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, self.context))
            gp.check_result(gp.gp_file_save(camera_file, target))
            # Count shutter count from image
            count = self.get_image_shutter(path + file_path.name)
            update_camera(str(count))

        except Exception as e:
            logger.error(e.message)
Пример #23
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
    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
Пример #25
0
    def capture(self):
        """Capture a page

        number -- An integer representing the current page number
        """
        if not config.DEBUGGING and not config.SKIP_CAMERA:
            file_path = gp.check_result(
                gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE,
                                     self.context))
            #print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
            camera_file = gp.check_result(
                gp.gp_camera_file_get(self.camera, file_path.folder,
                                      file_path.name, gp.GP_FILE_TYPE_NORMAL,
                                      self.context))
            filename = config.IMAGES_FOLDER + '/' + time.strftime(
                '%Y%m%d_%H%M%S') + '.jpg'
            gp.check_result(gp.gp_file_save(camera_file, filename))
        else:
            filename = config.IMAGES_FOLDER + config.DEBUGGING_IMAGE
        im = Image.open(filename).convert('RGB')
        im = im.rotate(config.ROTATION, expand=1)
        #im = im.crop((950, 400, 3200, 2300)) #hardcoded page boundaries. oeps
        # rotate image counter-clockwise if necesary
        #if(im.size[0] < im.size[1]):
        #im = im.rotate(90, expand=1)
        #im.save(filename[:-4]+'_edit.jpg')
        return im
Пример #26
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
Пример #27
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
Пример #28
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
Пример #29
0
def trigger_capture_and_save(camera, destination):
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    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, destination))
    return
Пример #30
0
 def download_picture(self, picture_path, store_path, keep_on_device=False):
     folder, filename = os.path.split(picture_path)
     with self._camera_object as co:
         camera_file = co.file_get(folder, filename, gp.GP_FILE_TYPE_NORMAL)
         gp.check_result(gp.gp_file_save(camera_file, store_path))
         # delete the file from the device
         if not keep_on_device:
             co.file_delete(folder, filename)
Пример #31
0
def get_store_and_show_image():
  file_path = gp.check_result(gp.gp_camera_capture(CAMERA, gp.GP_CAPTURE_IMAGE))
  log('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
  target = image_filename()
  print 'Copying image to {target}'.format(target=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(['open', target])
  return target
Пример #32
0
 def _capture_attempt(self, output_directory):
     file_path = gp.check_result(gp.gp_camera_capture(self._camera, gp.GP_CAPTURE_IMAGE, self._context))
     logging.debug('camera file path: {0}{1}'.format(file_path.folder, file_path.name))
     destination_file_name = datetime.now().strftime('%d-%H-%M-%S.jpg')
     destination_file_path = os.path.join(output_directory, destination_file_name)
     logging.debug('downloading image to {0}'.format(destination_file_path))
     camera_file = gp.check_result(gp.gp_camera_file_get(self._camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, self._context))
     gp.check_result(gp.gp_file_save(camera_file, destination_file_path))
     return destination_file_path
Пример #33
0
    def camera_file_get_and_save(self, file_path, target):
        camera_file = gp.check_result(
            gp.gp_camera_file_get(self.camera, file_path.folder,
                                  file_path.name, gp.GP_FILE_TYPE_NORMAL,
                                  self.context))

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

        return camera_file
Пример #34
0
def trigger_capture_and_save(camera, destination, context=None):
    if context is None:
        context = gp.Context()
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))
    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, destination))
    return
Пример #35
0
def main():

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

    while(True):
        result,image_file = gp.check_result(gp.gp_camera_wait_for_event(camera,gp.GP_EVENT_FILE_ADDED))
        if (result == gp.GP_EVENT_FILE_ADDED):
            # Get the image from the camera
            camera_file = gp.check_result(gp.gp_camera_file_get(
                                            camera, 
                                            image_file.folder, 
                                            image_file.name,
                                            gp.GP_FILE_TYPE_NORMAL))
            # Path where the image is to be saved
            target_path= os.path.join(os.getcwd(),image_file.name)
            print("Picture is saved to {}".format(target_path))
            gp.gp_file_save(camera_file, target_path)
    return 0
Пример #36
0
def download_all(camera, des: Path):

    fpath = Path(get_file_list(camera)[0])
    camera_file = camera.file_get(str(fpath.parent), str(fpath.name),
                                  gp.GP_FILE_TYPE_NORMAL)
    des_absolute_str = str(des.expanduser().joinpath(fpath.name).absolute())
    print(f"Copying to:{fpath.name}" + des_absolute_str)
    error = 0
    try:
        error = gp.check_result(gp.gp_file_save(camera_file, des_absolute_str))
    except gp.GPhoto2Error as ex:
        print(ex)
Пример #37
0
def capture_image(context, camera, filepath):
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))

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

    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))

    subprocess.call(['cp', target, filepath])
Пример #38
0
def copyFromCam(toFolder, file_path):
	global context, camera
	file_name = file_path.name
	target = os.path.join(toFolder, file_name)
	if not isJpg(file_name):
		print("encountered RAW file, putting in 'raw' subdir")
		target = os.path.join(toFolder, "raw", file_name)
		mkdirP(os.path.join(toFolder, "raw"))
	print('Copying image to', target)
	camera_file = gp.check_result(gp.gp_camera_file_get(
			camera, file_path.folder, file_name,
			gp.GP_FILE_TYPE_NORMAL, context))
	gp.check_result(gp.gp_file_save(camera_file, target))
Пример #39
0
def capture_image(camera, context, name):
    """
    Use gphoto to capture an image and retrieve it.
    Place the file in /tmp/name
    """
    file_path = gp.check_result(gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))
    target = os.path.join("/tmp", name)
    print "Copying image to {0}".format(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))
Пример #40
0
 def copy_file(self, file_path, prefix="", stubfn=""):
     (camera, context) = self.camera
     target_fn = file_path.name
     target_fn = os.path.splitext(target_fn)
     target_fn = target_fn[0] + stubfn + target_fn[1]
     target_fn = os.path.join(prefix, target_fn)
     print('Copying image to %s' % target_fn)
     res = gp.gp_camera_file_get(camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)
     camera_file = gp.check_result(res)
     res = gp.gp_file_save(camera_file, target_fn)
     gp.check_result(res)
     self.last_image = target_fn
     return target_fn
Пример #41
0
def copyFromCam(toFolder, file_path):
    global context, camera
    file_name = file_path.name
    target = os.path.join(toFolder, file_name)
    if not isJpg(file_name):
        print("encountered RAW file, putting in 'raw' subdir")
        target = os.path.join(toFolder, "raw", file_name)
        mkdirP(os.path.join(toFolder, "raw"))
    print('Copying image to', target)
    camera_file = gp.check_result(
        gp.gp_camera_file_get(camera, file_path.folder, file_name,
                              gp.GP_FILE_TYPE_NORMAL, context))
    gp.check_result(gp.gp_file_save(camera_file, target))
Пример #42
0
 def download_all_files_on_camera(self, prefix='', stubfn=''):
     pics = self.get_files_on_camera()
     (camera, context) = self.camera
     files = []
     for (path, fn) in pics:
         if fn.lower().endswith("cr2"):
             _type = gp.GP_FILE_TYPE_RAW
         else:
             _type = gp.GP_FILE_TYPE_NORMAL
         target_fn = os.path.splitext(fn)
         target_fn = target_fn[0] + stubfn + target_fn[1]
         target_fn = os.path.join(prefix, target_fn)
         camera_file = gp.check_result(gp.gp_camera_file_get(camera, path, fn, _type, context))
         gp.check_result(gp.gp_file_save(camera_file, target_fn))
Пример #43
0
 def __take_pic(self):
     print 'camera.__take_pic'
     target = './data/preview.jpg'
     if not self.use_real_camera:
         pass
         #self.pic_taken.emit('test.jpg')
     else:
         self.__apply_settings(self.__capture_settings)
         file_path = gp.check_result(gp.gp_camera_capture(self.__camera, gp.GP_CAPTURE_IMAGE, self.__context))
         camera_file = gp.check_result(gp.gp_camera_file_get(
             self.__camera, file_path.folder, file_path.name,
             gp.GP_FILE_TYPE_NORMAL, self.__context))
         print camera_file
         gp.check_result(gp.gp_file_save(camera_file, target))
     self.pic_taken.emit(target)
Пример #44
0
 def take_picture_thread(self, stop):
    self.go_button.setEnabled(False)
    self.stop_button.setEnabled(True)
    if self.get_parameter('shutterspeed')[1] != 'bulb':
         self.text_line.setText('Capturing...')
         error, self.file_path = gphoto2.gp_camera_capture(self.camera, gphoto2.GP_CAPTURE_IMAGE, self.context)
         camera_file = gphoto2.check_result(gphoto2.gp_camera_file_get(self.camera, self.file_path.folder, self.file_path.name, gphoto2.GP_FILE_TYPE_NORMAL, self.context))
         error = gphoto2.gp_file_save(camera_file, self.file_path.name)
         img_num = 1
         while os.path.isfile(self.current_picture):
             self.current_picture = 'IMG_'+str(img_num).zfill(4)+'.CR2'
             img_num = img_num + 1
         if hasattr(self, 'file_path'):
             os.rename(self.file_path.name, self.current_picture)
         raw = rawpy.imread(self.current_picture)
         image = raw.postprocess(user_flip=False, output_bps=8)
         image = cv2.resize(image,(768, 512))
         self.myImage = QtGui.QImage(image.astype(numpy.uint8), 768, 512, QtGui.QImage.Format_RGB888)
         self.text_line.setText('Done')
         self.image_event = 1
         self.update()
    else:
        secs = int(self.bulb_time.text())
        i = 0
        while i < int(self.bulb_pics.text()) and not stop.isSet():
           self.file_path = self.get_bulb_picture(secs, stop)
           img_num = 1
           while os.path.isfile(self.current_picture):
               self.current_picture = 'IMG_'+str(img_num).zfill(4)+'.CR2'
               img_num = img_num + 1
           if hasattr(self, 'file_path'):
               os.rename(self.file_path.name, self.current_picture)
           raw = rawpy.imread(self.current_picture)
           image = raw.postprocess(user_flip=False, output_bps=8)
           image = cv2.resize(image,(768, 512))
           self.myImage = QtGui.QImage(image.astype(numpy.uint8), 768, 512, QtGui.QImage.Format_RGB888)
           self.text_line.setText('Image '+str(i+1)+" of "+self.bulb_pics.text()+' done')
           self.image_event = 1
           self.update()
           i = i + 1
        if stop.isSet():
           self.text_line.setText('Interruped by user!')
        stop.clear()
    if hasattr(self, 'file_path'):
        self.solve_button.setEnabled(True)
        self.solve_scale.setEnabled(True)
    self.go_button.setEnabled(True)
    self.stop_button.setEnabled(False)
Пример #45
0
def _capture_image(camera, context, settings):
    print "Capturing Image"
    if settings:
        set_iso(str(ISO_CONSTANTS[settings['iso']]), camera, context)
        set_aperture(APERTURE_CONSTANTS[settings['f-number']], camera, context)
        set_shutterspeed(SHUTTER_SPEED_CONSTANTS[settings["shutterspeed2"]], camera, context)
    # Image being captured and stored on camera
    image_path = gp.check_result(gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))
    # Grabbing timestamp for unique file name
    timestamp = int(time.time())
    extension = image_path.name.split('.')[1]
    image_name = "TST_{}.".format(timestamp) + extension
    target_path = os.path.join(os.getcwd()+'/images', image_name)
    # "Grunt" work to move the file off camera
    image_file = gp.check_result(gp.gp_camera_file_get(camera, image_path.folder, image_path.name, gp.GP_FILE_TYPE_NORMAL, context))
    gp.check_result(gp.gp_file_save(image_file, target_path))
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
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
Пример #48
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
Пример #49
0
 def get_bulb_picture(self, secs, stop):
     self.set_parameter('bulb', 1)
     i = 0
     while i < secs and not stop.isSet():
         time.sleep(1)
         self.text_line.setText('Elapsed '+str(i+1)+' of '+str(secs)+' secs')
         i = i + 1
     self.set_parameter('bulb', 0)
     self.text_line.setText('Saving image...')
     time.sleep(2)
     status = 0
     i = 0
     while status != 2:
         error, status, self.file_path = gphoto2.gp_camera_wait_for_event(self.camera, i, self.context)
         i = i + 1
     camera_file = gphoto2.check_result(gphoto2.gp_camera_file_get(self.camera, self.file_path.folder, self.file_path.name, gphoto2.GP_FILE_TYPE_NORMAL, self.context))
     error = gphoto2.gp_file_save(camera_file, self.file_path.name)
     self.text_line.setText('Done')
     return self.file_path
Пример #50
0
    def capture_and_download(self, filename):

        self.state = self.STATE_BUSY
        
        try:
            error, file_path = gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE)
            gp.check_result(error)

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

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

            error = gp.gp_file_save(camera_file, os.path.join(*filename))
            gp.check_result(error)
        except Exception as e:
            raise e
        finally:
            self.state = self.STATE_CONNECTED
Пример #51
0
def take_photo():
    context = gp.Context()
    camera = gp.Camera()
    camera.init(context)

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

    # TODO - label the photos by date - YYYY-MM-DD-HH-MM-SS or something.
    datestr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S:%f ')
    target = os.path.join(settings.originals_dir, datestr + file_path.name)
    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_file_delete(
            camera,
            file_path.folder,
            file_path.name,
            context
        )
    )
    gp.gp_camera_exit(camera, context)

    return target
Пример #52
0
    def capture(self, n=1, camera = None, exposition = None, iso = None, focus = None, Zoom = None, save = True, publish = False, name = None):
        T_start = time.time()
        try:
            if not name:
                name = self.getCaptureName(extension = '')
            filename = '/home/odroid/robozor/', name + '_'+time.strftime("%Y%m%d-%H%M%S", time.gmtime())+'.cr2'
            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))
            print'Capturing image', self.context, self.camera

            file_path = gp.check_result(gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_IMAGE, self.context))
            print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
            target = os.path.join(filename)
            self.publishCR2(file = filename)
            print('Copying image to', target)
            camera_file = gp.check_result(gp.gp_camera_file_get(self.camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, self.context))
            gp.check_result(gp.gp_file_save(camera_file, target))
            gp.check_result(gp.gp_camera_exit(self.camera, self.context))
            return True 
        except Exception, e:
            rospy.logerr(e)
            return False
Пример #53
0
def getPicture(camera,context):
  print('Capturing image')
  showCapture(getClockFile(),(400,400))
  pygame.display.flip()
  current=os.path.join(TMPPATH,getImageName())
  if os.path.exists(current):
    os.unlink(current)
  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))
  if not os.path.exists(TMPPATH):
    os.makedirs(TMPPATH)
  target = os.path.join(TMPPATH, getImageName(False))
  print('Copying image to', target)
  try:
    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))
  except:
    pass
  rt=gp.gp_camera_file_delete(camera,file_path.folder,file_path.name,context)
  showCapture(target)
  return target
def capture_preview(camera, context, filename='capture_preview.jpg'):
        """ Capture a preview image """
        camfile = gp.check_result(gp.gp_file_new())
        gp.gp_camera_capture_preview(camera, camfile, context)
        gp.gp_file_save(camfile, 'capture_preview.jpg')
        gp.gp_file_unref(camfile)        
Пример #55
0
import gphoto2 as gp
import time
import os
import subprocess

#Open Camera
context = gp.Context()
camera = gp.Camera()
camera.init(context)

#Get Summary
text = camera.get_summary(context)
print('Summary')
print('=======')
print(str(text))

#Capture Image
file_path=gp.check_result( camera.capture(gp.GP_CAPTURE_IMAGE, context))
print('Camera file path: ' + file_path.folder + file_path.name)
target = os.path.join('/tmp', file_path.name)
camera_file = gp.check_result(camera.file_get(file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context))
gp.check_result(gp.gp_file_save(camera_file, target))

#Show the Image
subprocess.call(['fim', target])

#Exit session
camera.exit(context)