使用PyPortal展示克利夫兰艺术博物馆的艺术品
- shaoziyang
- 帖子: 3919
- 注册时间: 2019年 10月 21日 13:48
使用PyPortal展示克利夫兰艺术博物馆的艺术品
介绍
如今,不仅在博物馆内,在室外都在扩大公众对其艺术收藏品的访问。数字化举措将曾经被归入博物馆范围的艺术品带给了21世纪的全球观众。这些现代博物馆已实质上成为新的内容提供商。就像提供视频和音乐内容的现代公司Netflix和Pandora一样,博物馆通过收集绘画,照片,珠宝和其他媒体而成为自己的内容提供商。对这些收藏进行数字化处理并使其可公开获取,将这些材料吸引给全球读者。
克利夫兰艺术博物馆就是此类博物馆中的佼佼者。
克利夫兰艺术博物馆
克利夫兰艺术博物馆(CMA)位于俄亥俄州克利夫兰,拥有来自世界各地的61,000多件艺术品。它成立于1913年,以其拥有的亚洲和埃及艺术品而享誉国际。2018年有超过770,000人参观了博物馆。CMA于2019年1月23日宣布,其藏品中超过31,000张艺术品的数字图像将在公共领域提供。收藏品中包含数十种艺术类型,包括绘画,素描,照片,硬币和珠宝。所有这些图像都可以通过Creative Commons Zero(CC0)许可获得,该许可允许人们共享,协作,重新混合和重用集合中的图像以用于商业和非商业用途。CMA还创建了一个免费的API,该API允许程序轻松检索有关每个图像的信息。
使用Art PyPortal框架
该项目使用在PyPortal上运行的CircuitPython访问CMA API。它使用API从集合中选择一个随机项目。它使用Adafruit IO图像转换服务将来自集合的JPEG图像转换并重新调整为BMP图像,并调整为PyPortal的尺寸。最后,将转换后的图像下载到PyPortal进行显示。PyPortal的一项新功能允许正确缩放人像图像,这是此项目的一项重要功能。
给设备加电时,PyPortal在连接到互联网并检索其第一张图像时会显示一个Cleveland艺术博物馆横幅。PyPortal从集合中可用的31,000多种图像中检索图像,并将其标题和标题显示在屏幕底部。
默认情况下,显示屏每5分钟自动更新一次(可以在代码中更改),这需要3个月(24x7)的时间才能显示全部图像。您也可以通过使用PyPortal的触摸屏触摸屏幕上的任意位置来手动更新显示。触摸屏幕时,显示屏右下角将出现一个红色圆圈,表示当前正在更新屏幕。在通过自动或手动更新进行屏幕更新时,触摸屏将处于非活动状态。请注意,Adafruit IO图像转换器服务受速率限制,因此图像之间最短间隔时间是一分钟。
更多内容请参考:
https://learn.adafruit.com/cleveland-mu ... e/overview
- shaoziyang
- 帖子: 3919
- 注册时间: 2019年 10月 21日 13:48
Re: 使用PyPortal展示克利夫兰艺术博物馆的艺术品
需要先安装下面的库:
- adafruit_bitmap_font
- adafruit_bus_device
- adafruit_display_shapes
- adafruit_display_text
- adafruit_esp32spi
- adafruit_io
- adafruit_logging.mpy
- adafruit_pyportal.mpy
- adafruit_requests.mpy
- adafruit_sdcard.mpy
- adafruit_touchscreen.mpy
- neopixel.mpy
Code: Select all
import time
import random
import board
from adafruit_pyportal import PyPortal
from adafruit_display_shapes.circle import Circle
WIDTH = board.DISPLAY.width
HEIGHT = board.DISPLAY.height
#pylint: disable=line-too-long
# these lines show the entire collection
APIURL = "https://openaccess-api.clevelandart.org/api/artworks?cc0=1&has_image=1&indent=2&limit=1&skip="
IMAGECOUNT = 31954
# uncomment these lines to show just paintings
# APIURL = "https://openaccess-api.clevelandart.org/api/artworks?cc0=1&has_image=1&indent=2&limit=1&type=Painting&skip="
# IMAGECOUNT = 3223
BACKGROUND_FILE = "/background.bmp"
if WIDTH > 320:
BACKGROUND_FILE = "/background_480.bmp"
pyportal = PyPortal(default_bg=BACKGROUND_FILE,
image_json_path=["data", 0, "images", "web", "url"],
image_dim_json_path=(["data", 0, "images", "web", "width"],
["data", 0, "images", "web", "height"]),
image_resize=(WIDTH, HEIGHT - 15),
image_position=(0, 0),
text_font="/fonts/OpenSans-9.bdf",
json_path=["data", 0, "title"],
text_position=(4, HEIGHT - 9),
text_color=0xFFFFFF)
circle = Circle(WIDTH - 8, HEIGHT - 7, 5, fill=0)
pyportal.splash.append(circle)
loopcount = 0
errorcount = 0
while True:
response = None
try:
circle.fill = 0xFF0000
itemid = random.randint(1, IMAGECOUNT)
# itemid = 20 # portrait mode example
# itemid = 21 # landscape mode example
print("retrieving url:", APIURL + str(itemid))
response = pyportal.fetch(APIURL + str(itemid))
circle.fill = 0
print("Response is", response)
loopcount = loopcount + 1
except (RuntimeError, KeyError, TypeError) as e:
print("An error occured, retrying! -", e)
print("loop counter:", loopcount)
assert errorcount < 20, "Too many errors, stopping"
errorcount = errorcount + 1
time.sleep(60)
continue
errorcount = 0
stamp = time.monotonic()
# wait 5 minutes before getting again
while (time.monotonic() - stamp) < (5*60):
# or, if they touch the screen, fetch immediately!
if pyportal.touchscreen.touch_point:
break
-
- 随机主题
- 回复总数
- 阅读次数
- 最新文章
-
- 1回复总数
- 2259 阅读次数
- 最新文章 由 shaoziyang
2019年 12月 19日 11:31
-
- 1回复总数
- 2262 阅读次数
- 最新文章 由 shaoziyang
2019年 12月 19日 11:36
-
- 1回复总数
- 2723 阅读次数
- 最新文章 由 shaoziyang
2019年 12月 19日 11:38