Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def open_camera(self):
# the following needs to be changed into some
# kind of context manager aware delay to allow
# the camera to get ready in a context manager
release_from_tight_grip_of_operating_system()
ctx = gp.gp_context_new()
error, camera = gp.gp_camera_new()
gp.check_result(gp.gp_camera_init(camera, ctx))
# TODO: check if camera cannot be used for some reason
self._camera = camera
self._context = ctx
# use Python logging
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
# get user value
if len(sys.argv) != 2:
print('One command line parameter required')
return 1
try:
value = int(sys.argv[1])
except:
print('Integer parameter required')
return 1
# open camera connection
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
# get configuration tree
config = gp.check_result(gp.gp_camera_get_config(camera))
# find the capture target config item
capture_target = gp.check_result(
gp.gp_widget_get_child_by_name(config, 'capturetarget'))
# check value in range
count = gp.check_result(gp.gp_widget_count_choices(capture_target))
if value < 0 or value >= count:
print('Parameter out of range')
return 1
# set value
value = gp.check_result(gp.gp_widget_get_choice(capture_target, value))
gp.check_result(gp.gp_widget_set_value(capture_target, value))
# set config
gp.check_result(gp.gp_camera_set_config(camera, config))
# clean up
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))
# required configuration will depend on camera type!
print('Checking camera config')
# get configuration tree
config = gp.check_result(gp.gp_camera_get_config(camera))
# find the image format config item
# camera dependent - 'imageformat' is 'imagequality' on some
OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat')
if OK >= gp.GP_OK:
# get current setting
value = gp.check_result(gp.gp_widget_get_value(image_format))
# make sure it's not raw
if 'raw' in value.lower():
print('Cannot preview raw images')
return 1
# find the capture size class config item
# need to set this on my Canon 350d to get preview to work at all
directory_name = experiment_basename + '_gphoto2'
self.destination = os.path.join(home_directory, directory_name)
if os.path.exists(self.destination):
pass
else:
os.mkdir(self.destination)
# initialize the node
rospy.init_node('gphoto2_' + nodenum)
self.nodename = rospy.get_name().rstrip('/')
self.nodenum = nodenum
#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))
self.synchronize_camera_timestamp()
self.subTrackedObjects = rospy.Subscriber('/multi_tracker/' + nodenum + '/' + topic, Float32MultiArray, self.gphoto_callback)
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
camera = gp.check_result(gp.gp_camera_new())
gp.check_result(gp.gp_camera_init(camera))
print('Getting list of files')
files = list_files(camera)
if not files:
print('No files found')
return 1
path = files[0]
print('Copying %s to memory' % path)
folder, name = os.path.split(path)
camera_file = gp.check_result(gp.gp_camera_file_get(
camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
## # read file data using 'slurp' and a buffer allocated in Python
## info = gp.check_result(
## gp.gp_camera_file_get_info(camera, folder, name))
## file_data = bytearray(info.file.size)
## count = gp.check_result(gp.gp_file_slurp(camera_file, file_data))
## print(count, 'bytes read')
def main():
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = 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):