本文整理汇总了Python中photo.Photo类的典型用法代码示例。如果您正苦于以下问题:Python Photo类的具体用法?Python Photo怎么用?Python Photo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Photo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getRandomPhoto
def getRandomPhoto(photos):
print('Selecting a random photo')
photo = choice(photos)
p = Photo(photo['imgUrl'])
p.retrieve()
photo['imageData'] = p.getData()
return photo
示例2: getWordList
def getWordList(self, event):
# word_list is a list of (word, freq)
cp = CaptionParser(True)
for photo in event['photos']:
photo = Photo(photo)
cp.insertCaption(photo.getCaption())
return cp.getTopWords(-1, False)
示例3: direction_without_camera
def direction_without_camera(self):
photo = Photo(1024, 768, "0", 30)
images = photo.use_photos_test_images()
for image in images:
cmd = "cp photos_test/%s photos/direction.jpg" % image
system(cmd)
self.move_robot(photo)
示例4: scaleImage
def scaleImage(filename, filigrane=None):
"""Common processing for one image :
- create a subfolder "scaled" and "thumb"
- populate it
@param filename: path to the file
@param filigrane: None or a Signature instance (see imagizer.photo.Signature)
"""
rootdir = os.path.dirname(filename)
scaledir = os.path.join(rootdir, config.ScaledImages["Suffix"])
thumbdir = os.path.join(rootdir, config.Thumbnails["Suffix"])
fileutils.mkdir(scaledir)
fileutils.mkdir(thumbdir)
photo = Photo(filename, dontCache=True)
param = config.ScaledImages.copy()
param.pop("Suffix")
param["strThumbFile"] = os.path.join(scaledir, os.path.basename(filename))[:-4] + "--%s.jpg" % config.ScaledImages["Suffix"]
photo.saveThumb(**param)
param = config.Thumbnails.copy()
param.pop("Suffix")
param["strThumbFile"] = os.path.join(thumbdir, os.path.basename(filename))[:-4] + "--%s.jpg" % config.Thumbnails["Suffix"]
photo.saveThumb(**param)
if filigrane is not None:
filigrane.substract(photo.pil).save(filename, quality=config.FiligraneQuality, optimize=config.FiligraneOptimize, progressive=config.FiligraneOptimize)
try:
os.chmod(filename, config.DefaultFileMode)
except OSError:
logger.warning("in scaleImage: Unable to chmod %s" % filename)
示例5: save_avatar
def save_avatar(self, filepath):
photo = Photo()
photo.filepath = filepath
photo.us_id = self.id
DBSession.add(photo)
DBSession.flush()
return photo
示例6: load_all_photos_by_likes
def load_all_photos_by_likes(self, db, cursor, limit=10):
sql = (
"SELECT photos.id, photos.fb_id, photos.filename, photos.caption, \
photos.owner_id, photos.state, photos.created_at, photos.approved_at, \
likes_count.count \
FROM photos \
LEFT JOIN (SELECT photo_id, count(*) AS count FROM likes GROUP BY photo_id) AS likes_count \
ON photos.id = likes_count.photo_id \
ORDER BY likes_count.count DESC, \
photos.approved_at DESC LIMIT %d"
% limit
)
try:
cursor.execute(sql)
data = cursor.fetchall()
for row in data:
photo = Photo()
photo.load_from_tuple(row)
self.photos_list.append(photo)
return self.photos_list
except Exception, e:
raise e
示例7: _auto_rotate_thanks_to_exif
def _auto_rotate_thanks_to_exif(self, thumb=True):
tgetDir = "thumbs"
if not thumb:
tgetDir = "preview"
tmpFile = join(self.tempdir, "toto.jpg")
copy(self.exim1, tmpFile)
oldpwd = getcwd()
chdir(self.tempdir)
photo = Photo(tmpFile)
tmpDir = join(self.tempdir, tgetDir)
os.mkdir(tmpDir)
if not thumb:
photo.makeThumbnail(tgetDir)
else:
photo.makePreview(tgetDir)
# for d in walk(self.tempdir):
# print d
# uncomment to get this picture and check it (I use the handy xv)
# copy(photo.thumbPath, '/tmp/thumb.jpg')
chdir(oldpwd)
示例8: mergeWith
def mergeWith(self, event):
if type(event) is types.DictType:
event = Event(event)
event = event.toJSON()
photo_list1 = self._event['photos']
photo_list2 = event['photos']
new_photo_list = []
l1 = 0
l2 = 0
merged = 0
while l1 < len(photo_list1) and l2 < len(photo_list2):
p1 = Photo(photo_list1[l1])
p2 = Photo(photo_list2[l2])
compare = p1.compare(p2)
if compare == 1:
new_photo_list.append(photo_list1[l1])
l1 += 1
continue
if compare == -1:
new_photo_list.append(photo_list2[l2])
l2 += 1
merged += 1
continue
# compare == 0
new_photo_list.append(photo_list1[l1])
l1 += 1
l2 += 1
while l1 < len(photo_list1):
new_photo_list.append(photo_list1[l1])
l1 += 1
while l2 < len(photo_list2):
new_photo_list.append(photo_list2[l2])
l2 += 1
merged += 1
self._event['photos'] = new_photo_list
# update actual value
self.setActualValue(self._getActualValueByCounting())
# do not change the order of the following code
actual_value_1 = self._event['actual_value']
actual_value_2 = event['actual_value']
zscore1 = float(self._event['zscore'])
zscore2 = float(event['zscore'])
std1 = float(self._event['predicted_std'])
std2 = float(event['predicted_std'])
new_std = (std1 * actual_value_1 + std2 * actual_value_2) / (actual_value_1 + actual_value_2)
new_zscore = (zscore1 * actual_value_1 + zscore2 * actual_value_2) / (actual_value_1 + actual_value_2)
self.setZscore(new_zscore)
new_mu = actual_value_1 - new_zscore * new_std
self.setPredictedValues(new_mu, new_std)
return merged
示例9: save_photo
def save_photo(self, filepath, main=False):
photo = Photo()
photo.filepath = filepath
photo.product_id = self.id
photo.is_main = main
DBSession.add(photo)
DBSession.flush()
return photo
示例10: _getTopWords
def _getTopWords(self, k, stopword_removal=False):
caption_parser = CaptionParser(stopword_removal=stopword_removal)
for photo in self._event["photos"]:
p = Photo(photo)
caption = p.getCaption()
if not caption is None:
caption_parser.insertCaption(caption)
return caption_parser.getTopWords(k)
示例11: direction
def direction(self):
photo = Photo(260, 260, "180", 30)
i = 0
start = True
while i < 100:
photo.take_photo_with_picamera()
self.move_robot(photo)
i += 1
示例12: getCaptionPercentage
def getCaptionPercentage(self):
cap_number = 0
photos = self._event["photos"]
for photo in photos:
photo = Photo(photo)
cap_len = len(photo.getCaption())
if cap_len > 0:
cap_number += 1
return cap_number * 1.0 / len(photos)
示例13: _getTopWords
def _getTopWords(self, k, stopword_removal=False):
# get top words by counting the frequecy
text_parser = TextParser(stopword_removal=stopword_removal)
for photo in self._event['photos']:
p = Photo(photo)
caption = p.getCaption()
if not caption is None:
text_parser.insertCaption(caption)
return text_parser.getTopWords(k)
示例14: update_img
def update_img(self, user_list=None, force=False, token_list=token_list):
if user_list is None:
user_list = self._get_all_user()
album = Album()
photo = Photo()
for user in user_list:
album.update(token_list, user, force)
photo.update(token_list, user, force)
photo.update_data(user)
return True
示例15: getPhotosbyKeyword
def getPhotosbyKeyword(self, word):
# return a list of photos containg the word
res_photo = []
for photo in self._event['photos']:
cap = Photo(photo).getCaption()
if cap is None:
continue
cap = cap.lower()
if word in cap:
res_photo.append(photo)
return res_photo