def reload_gallery(self, request, **kwargs): reindex_gallery() galleryGalPath = get_gallery_file() galGallery = br.br_make_gallery(galleryGalPath) galTemplateList = br.br_load_from_gallery(galGallery) # compare and collect scores ntargets = br.br_num_templates(galTemplateList) logger.debug(str(ntargets) + " templates found in the gallery at " + galleryGalPath) res = str(ntargets) + " templates found in the gallery at " + galleryGalPath for r in range(ntargets): tmpl = br.br_get_template(galTemplateList, r) logger.debug("Filename = " + br.br_get_filename(tmpl)) response = self.create_response(request, res) br.br_free_template_list(galTemplateList) br.br_close_gallery(galGallery) return response
def obj_create(self, bundle, request=None, **kwargs): # create a new File bundle.obj = FaceSearch() # full_hydrate does the heavy lifting mapping the # POST-ed payload key/values to object attribute/values bundle = self.full_hydrate(bundle) file_data = bundle.data[u'file'].read() filename_name, file_extension = os.path.splitext(bundle.data[u'file'].name) # Load uploaded image with OpenBR facetmpl = br.br_load_img(file_data, len(file_data)) query = br.br_enroll_template(facetmpl) # Open the OpenBR gallery file galleryGalPath = get_gallery_file() galGallery = br.br_make_gallery(galleryGalPath) galTemplateList = br.br_load_from_gallery(galGallery) # compare and collect scores nqueries = br.br_num_templates(query) ntargets = br.br_num_templates(galTemplateList) scoresmat = br.br_compare_template_lists(galTemplateList, query) scores = [] for r in range(ntargets): for c in range(nqueries): # This is not a percentage match, it's a relative score similarity = br.br_get_matrix_output_at(scoresmat, r, c) tmpl = br.br_get_template(galTemplateList, r) # TODO: This doesn't seem to work through PyCharm, but does once deployed # Plus, it's not correlating filenames to templates correctly. #filename = br.br_get_filename(tmpl) #scores.append((os.path.basename(filename), similarity)) scores.append(('replace-me', similarity)) # clean up - no memory leaks br.br_free_template(facetmpl) br.br_free_template_list(query) br.br_free_template_list(galTemplateList) br.br_close_gallery(galGallery) scores.sort(key=lambda s: s[1], reverse=True) peeps = Person.objects.filter(pic_filename__in=dict(scores).keys()).values() # TODO: Make 15 a parameter - right now we return the top 15 results sorted_peeps = [] for s in scores[:15]: sorted_peeps.append(filter(lambda p: p['pic_filename'] == s[0], peeps)[0]) # bundle the search results bundle.obj.name = bundle.data[u'file'].name bundle.data.pop(u'file', None) bundle.data['meta'] = { "limit": len(peeps), "next": None, "offset": 0, "previous": None, "total_count": len(peeps) } bundle.data['objects'] = sorted_peeps bundle.data['scores'] = scores return bundle
def obj_create(self, bundle, request=None, **kwargs): # create a new File bundle.obj = FaceSearch() # full_hydrate does the heavy lifting mapping the # POST-ed payload key/values to object attribute/values bundle = self.full_hydrate(bundle) file_data = bundle.data[u'file'].read() filename_name, file_extension = os.path.splitext( bundle.data[u'file'].name) # Load uploaded image with OpenBR facetmpl = br.br_load_img(file_data, len(file_data)) query = br.br_enroll_template(facetmpl) # Open the OpenBR gallery file galleryGalPath = get_gallery_file() galGallery = br.br_make_gallery(galleryGalPath) galTemplateList = br.br_load_from_gallery(galGallery) # compare and collect scores nqueries = br.br_num_templates(query) ntargets = br.br_num_templates(galTemplateList) scoresmat = br.br_compare_template_lists(galTemplateList, query) scores = [] for r in range(ntargets): for c in range(nqueries): # This is not a percentage match, it's a relative score similarity = br.br_get_matrix_output_at(scoresmat, r, c) tmpl = br.br_get_template(galTemplateList, r) # TODO: This doesn't seem to work through PyCharm, but does once deployed # Plus, it's not correlating filenames to templates correctly. #filename = br.br_get_filename(tmpl) #scores.append((os.path.basename(filename), similarity)) scores.append(('replace-me', similarity)) # clean up - no memory leaks br.br_free_template(facetmpl) br.br_free_template_list(query) br.br_free_template_list(galTemplateList) br.br_close_gallery(galGallery) scores.sort(key=lambda s: s[1], reverse=True) peeps = Person.objects.filter( pic_filename__in=dict(scores).keys()).values() # TODO: Make 15 a parameter - right now we return the top 15 results sorted_peeps = [] for s in scores[:15]: sorted_peeps.append( filter(lambda p: p['pic_filename'] == s[0], peeps)[0]) # bundle the search results bundle.obj.name = bundle.data[u'file'].name bundle.data.pop(u'file', None) bundle.data['meta'] = { "limit": len(peeps), "next": None, "offset": 0, "previous": None, "total_count": len(peeps) } bundle.data['objects'] = sorted_peeps bundle.data['scores'] = scores return bundle