def vuforia_target(request, target_id): # Instantiatin Vuforia API vkeys = vuforia_keys(request) vuforia = Vuforia( access_key = vkeys.get('vuforia_access_key'), secret_key = vkeys.get('vuforia_secret_key'), ) if target_id: target_data = vuforia.get_target_by_id(target_id) return HttpResponse(json.dumps(target_data), content_type="application/json") else: return None
def delete_targets(): """ Remove Unbound Targets """ print "Running: delete_targets" vuforia_instances = [{ 'vuforia_access_key': DEFAULT_VUFORIA_ACCESS_KEY, 'vuforia_secret_key': DEFAULT_VUFORIA_ACCESS_KEY }] profiles = Profile.objects.all() for profile in profiles: vuforia_instances.append({ 'vuforia_access_key': str(profile.vuforia_access_key), 'vuforia_secret_key': str(profile.vuforia_secret_key) }) for instance in vuforia_instances: try: vuforia = Vuforia( access_key = instance.get('vuforia_access_key'), secret_key = instance.get('vuforia_secret_key'), ) targets = vuforia.get_targets() deleted_targets = 0 unbound_targets = 0 for target in targets: target_id = target.get('target_id') gallery = Gallery.objects(__raw__={'pictures.target_id': target_id}) if not gallery: print "Deleting Target: ", target_id unbound_targets+=1 try: vuforia.delete_target(u"".join(target_id)) deleted_targets+=1 except Exception as e: print e print 'Delected: %s targets of %s'%(deleted_targets, unbound_targets) except Exception as e: print e return 'Deleted Targets'
def handle_uploaded_file(request, file, obj_id=''): prefix = '%s_'%(obj_id) sufix = '' file_name = file_name_pattern( formatText(str(file)), prefix=prefix, sufix=sufix) base_path = urljoin(MEDIA_ROOT+"/", file_path_pattern(request)).replace("//","/") storage = DefaultFileStorage(location = base_path, base_url = MEDIA_URL) path = storage.save(file_name, file) # Post Image to Vuforia using RESTful API vkeys = vuforia_keys(request) vuforia = Vuforia( access_key = str(vkeys.get('vuforia_access_key')), secret_key = str(vkeys.get('vuforia_secret_key')) ) image_f = '' for chunk in file.chunks(): image_f+= chunk pil_img = Image.open(StringIO(str(image_f))) (width, height) = pil_img.size image_file = file image = base64.b64encode(str(image_f)) #================Meta Data Example================== # # metadata_file = open('[METADATA_FILE]') # metadata = base64.b64encode(metadata_file.read()) #=================================================== metadata = base64.b64encode( '%s'%(image_file) ) # Metadata Added/Overrided after submition by ./cron.py target_response = vuforia.add_target({ "name": file_name, "width": width, "image": image, "application_metadata": metadata, "active_flag": 1 }) return (path, target_response)