Beispiel #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)
Beispiel #2
0
def init():
    context = gp.gp_context_new()
    error, file = gp.gp_file_new()
    error, camera = gp.gp_camera_new()
    error = gp.gp_camera_init(camera, context)
    error, text = gp.gp_camera_get_summary(camera, context)

    gp.gp_camera_capture(camera, 0, context)
    print('Summary')
    print('=======')
    print(text.text)
    print(gp.gp_result_as_string(error))

    print("start")
    return camera, context
Beispiel #3
0
def takePic():
    global context, camera
    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))
    return file_path
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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)
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
Beispiel #8
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
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))
Beispiel #10
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
Beispiel #11
0
def take_picture(camera: gp.camera,
                 rotation_pos: int, declination_pos: int,
                 queue: beanstalk.Connection) -> str:
    """take a picture and save it to the USB drive
    or the google drive, if specified"""

    # take the picture
    file_path = gp.check_result(gp.gp_camera_capture(
        camera, gp.GP_CAPTURE_IMAGE))
    file_name = 'P{dec:02d}{rot:02d}_'.\
                    format(dec=declination_pos, rot=rotation_pos) + file_path.name

    # read the photo from the camera
    camera_file = gp.check_result(gp.gp_camera_file_get(camera,
                                                        file_path.folder,
                                                        file_path.name,
                                                        gp.GP_FILE_TYPE_NORMAL))

    # if a google drive isn't specified, write to the local USB drive
    # read the image from the camera into memory
    # and upload it
    file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))

    # okay, upload to the Google drive via a thread...
    byte_stream = io.BytesIO(file_data)
    camera_bytes = byte_stream.read(-1)
    job = {'task': 'photo',
           'filename': file_name,
           'data': base64.encodebytes(camera_bytes).decode('ascii')}
    # now send the photo to the Google Drive process
    queue.use(google_drive.GDRIVE_QUEUE)
    job_str = json.dumps(job)
    print("photo job size is {0} bytes".format(len(job_str)))
    queue.put(job_str)
    return file_name
Beispiel #12
0
def takePic():
	global context, camera
	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))
	return file_path
Beispiel #13
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
Beispiel #14
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
Beispiel #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)})
Beispiel #16
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
    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")
Beispiel #18
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 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)
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
    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
Beispiel #22
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))
Beispiel #23
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
Beispiel #24
0
    def camera_capture_video(self, video_duration):
        file_path = gp.check_result(
            gp.gp_camera_capture(self.camera, gp.GP_CAPTURE_MOVIE,
                                 self.context))

        # TODO : see how it goes : video_duration

        return file_path
Beispiel #25
0
async def set_capture(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))
Beispiel #26
0
 def capture(self, copy=False, prefix="", stubfn=""):
     (camera, context) = self.camera
     res = gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context)
     file_path = gp.check_result(res)
     if copy:
         return self.copy_file(file_path, prefix=prefix, stubfn=stubfn)
     else:
         return file_path
Beispiel #27
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
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
Beispiel #29
0
        def capture():
            path = gp.check_result(gp.gp_camera_capture(self._camera, gp.GP_CAPTURE_IMAGE, self._context))

            file = gp.check_result(gp.gp_camera_file_get(
                self._camera, path.folder, path.name,
                gp.GP_FILE_TYPE_NORMAL, self._context))

            data = gp.check_result(gp.gp_file_get_data_and_size(file))
            return bytes(data)
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
Beispiel #31
0
 def _do_capture(self):
     # capture actual image (saved to camera memory card and also downloaded)
     OK, camera_file_path = gp.gp_camera_capture(
         self.camera, gp.GP_CAPTURE_IMAGE, self.context)
     if OK < gp.GP_OK:
         print('Failed to capture')
         return
     camera_file = self.camera.file_get(
         camera_file_path.folder, camera_file_path.name,
         gp.GP_FILE_TYPE_NORMAL, self.context)
     self._send_file(camera_file)
Beispiel #32
0
 def capture_filepath(self):
     self.log("Capturing")
     # Enter preview mode so we won't trigger autofocus engine
     if self.controlfocus and not self.in_preview:
         self.enter_preview()
     camerafilepath = gp.check_result(gp.gp_camera_capture(
             self.camera,
             gp.GP_CAPTURE_IMAGE,
             self.context))
     self.in_preview = False
     return camerafilepath
Beispiel #33
0
 def _do_capture(self):
     # capture actual image
     OK, camera_file_path = gp.gp_camera_capture(
         self.camera, gp.GP_CAPTURE_IMAGE)
     if OK < gp.GP_OK:
         print('Failed to capture')
         self.running = False
         return
     camera_file = self.camera.file_get(
         camera_file_path.folder, camera_file_path.name,
         gp.GP_FILE_TYPE_NORMAL)
     self._send_file(camera_file)
Beispiel #34
0
 def _do_capture(self):
     # capture actual image
     OK, camera_file_path = gp.gp_camera_capture(
         self.camera, gp.GP_CAPTURE_IMAGE, self.context)
     if OK < gp.GP_OK:
         print('Failed to capture')
         self.running = False
         return
     camera_file = self.camera.file_get(
         camera_file_path.folder, camera_file_path.name,
         gp.GP_FILE_TYPE_NORMAL, self.context)
     self._send_file(camera_file)
Beispiel #35
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])
Beispiel #36
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))
Beispiel #37
0
def camera_capture_image(camera, path='/tmp'):
    # initialize camera
    gp.check_result(gp.gp_camera_init(camera))
    # capture a image
    file_path = gp.check_result(gp.gp_camera_capture(
            camera, gp.GP_CAPTURE_IMAGE))
    # store a image
    target = os.path.join(path, 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))
    # subprocess.call(['xdg-open', target])
    # exit camera
    gp.check_result(gp.gp_camera_exit(camera))
Beispiel #38
0
def take_photo(save_folder):
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    logging.debug('Capturing image')
    file_path = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE))
    timestr = time.strftime("%Y%m%d_%H%M%S")
    target = os.path.join(save_folder, timestr + ".jpg")
    logging.debug('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))
    gp.check_result(gp.gp_file_save(camera_file, target))
    return target
def capture():
    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
Beispiel #40
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))
Beispiel #41
0
def captureandsave(camera, context):

    #Capture Action
    cameraCapturePath = gp.check_result(
        gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context))

    #Making Target Save photo_local_root Dir
    target = os.path.join(tl.getConfig('photo_local_root'),
                          cameraCapturePath.name)

    #Grab Captured Image Extension
    captureFileExtension = pathlib.Path(cameraCapturePath.name).suffix

    #GP_FILE_TYPE_NORMAL for JPEG; GP_FILE_TYPE_RAW for RAW
    if (tl.getConfig('FILE_TYPE') == 'RAW'):
        camera_file = gp.check_result(
            gp.gp_camera_file_get(camera, cameraCapturePath.folder,
                                  cameraCapturePath.name, gp.GP_FILE_TYPE_RAW,
                                  context))
    elif (tl.getConfig('FILE_TYPE') == 'JPEG'):
        camera_file = gp.check_result(
            gp.gp_camera_file_get(camera, cameraCapturePath.folder,
                                  cameraCapturePath.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, cameraCapturePath.folder,
                                 cameraCapturePath.name, context))

    #Rename Based on EXIF Data
    target_open = open(target, 'rb')
    exif_tags = exifread.process_file(target_open, \
                                 stop_tag='EXIF DateTimeOriginal')
    for tag in exif_tags.keys():
        #Only Perform Following if tag is Date/Time
        #Change file extension here for RAW/JPEG
        if tag in ('EXIF DateTimeOriginal'):
            file_name = exif_todatetimestr(
                exif_tags[tag]) + captureFileExtension
            file_dir = os.path.join(tl.getConfig('photo_local_root'),
                                    exif_todatestr(exif_tags[tag]))

            #Check existence of file_dir, the create it if false
            if not os.path.exists(file_dir):
                os.makedirs(file_dir)

            #Rename and move the captured image then sleep
            shutil.move(target, os.path.join(file_dir, file_name))
            time.sleep(3)
Beispiel #42
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)
Beispiel #43
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)
Beispiel #44
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 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 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():
    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
Beispiel #48
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
Beispiel #49
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
    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
Beispiel #51
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
	camera = gp.check_result(gp.gp_camera_new())
	gp.check_result(gp.gp_camera_init(camera, context))

	photoangles = []
	for i in range(37):
		photoangles.append([i*10])
	print photoangles


	notest = [[0], [10]]

	for coords in photoangles:
		stage.move(coords, 0)

		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))
		subprocess.call(['xdg-open', target])

		status = stage.aAxisNode.spinStatusRequest()
		while status['stepsRemaining'] > 0:
			time.sleep(0.001)
			status = stage.aAxisNode.spinStatusRequest()	
	
	gp.check_result(gp.gp_camera_exit(camera, context))