本文整理汇总了Python中picture.Picture.get_public_url方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.get_public_url方法的具体用法?Python Picture.get_public_url怎么用?Python Picture.get_public_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类picture.Picture
的用法示例。
在下文中一共展示了Picture.get_public_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _is_int
# 需要导入模块: from picture import Picture [as 别名]
# 或者: from picture.Picture import get_public_url [as 别名]
class Worker:
pic = Picture
task_name = ''
task_payload = ''
def _is_int(self, s):
try:
int(s)
return True
except ValueError:
return False
def __init__(self, task_name, task_payload):
"""
Worker constructor. Prepares the picture to work on.
:param task_name:
:param task_payload:
:return: A Worker object
"""
self.task_name = task_name
self.task_payload = task_payload
p, image_name = task_name.split('--')
self.pic = Picture('{0}.jpg'.format(image_name))
def do_your_thing(self):
"""
Self managed thread that makes the necessary work to get the digits from the user provided picture. At the
end calls _post_result_to_app_engine to notify app engine about the result of the processing.
:return:
"""
reading = ''
r = requests.get('{0}/process_image?image={1}&model={2}'.format(VMX_SERVER, self.pic.get_public_url(), MODEL))
if r.status_code == 200:
number = []
objects = r.json()['objects']
for o in objects:
try:
digit = Detection(o)
except FalseDetectionException:
pass
else:
number.append(digit)
config.logging.debug('Detected: [{0}] with a score of: {1}'.format(digit.value, digit.score))
config.logging.debug('End getting digits')
try:
# Get digit with highest score
number.sort(key=lambda n: n.score, reverse=True)
highest_score = number[0]
config.logging.debug('The digit with highest score is: {0}, score {1}'
.format(highest_score.value, highest_score.score))
# Get digit size
digit_size = highest_score.endX - highest_score.beginX
config.logging.debug('Digit size = {0}'.format(digit_size))
# Sort digits according to location on image to generate the reading
count = 0
number.sort(key=lambda n: n.center)
for num in number:
if count > 0:
pixels_between = num.beginX - number[count-1].endX
config.logging.debug('{0} Pixels between {1} and {2}'.format(pixels_between,
number[count-1].value,
num.value))
if pixels_between < digit_size*2:
# Contiguous digits
reading += str(num.value)
else:
# To much pixels between characters we missed one! =(
reading += '_{0}'.format(str(num.value))
else:
config.logging.debug('Starting distance measurement with: {0}'.format(num.value))
reading += str(num.value)
count += 1
config.logging.info('Number in image [{0}]: {1}'.format(self.pic.get_public_url(), reading))
# Check if reading is good and complete
if self._is_int(reading):
if len(reading) > 4:
try:
r = self._post_result_to_app_engine(reading)
if r:
config.logging.info('Result successfully posted to AppEngine!')
except Exception as e:
# TODO: Retry request ..
config.logging.error('Error posting to AppEngine: {0}, retry task!'.format(e.__str__()))
else:
# Wrong reading notification (Incomplete)
raise IndexError
else:
# Wrong reading notification (Not an Int)
raise IndexError
except IndexError:
config.logging.warning('The response [{0}] is not valid. Something is wrong!'.format(reading))
try:
r = self._notify_error_to_app_engine('Not enough characters recognized, '
'successfully recognized: {0}'.format(reading))
#.........这里部分代码省略.........