Last active
January 13, 2018 12:07
-
-
Save sumomoneko/56142201b44ac3dbf1dfe22bedd02323 to your computer and use it in GitHub Desktop.
画像からいくつかのピクセルを抜き取り平均の色を得る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getColor(): | |
r = requests.get("http://example.jp/live.jpg") | |
if r.ok: | |
image = PIL.Image.open(io.BytesIO(r.content)) | |
# 座標 x,y = (10,10), (100, 10), ..., (600, 20) の平均 r,g,b を得る | |
return map(statistics.mean, | |
zip(*(image.getpixel(pos) for pos in itertools.product((10, 100, 200, 300, 400, 500, 600), (10, 20))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment