Skip to content

Instantly share code, notes, and snippets.

@3110
Last active May 17, 2022 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3110/d49f5fe7631c974c9b4d137da82e79bd to your computer and use it in GitHub Desktop.
Save 3110/d49f5fe7631c974c9b4d137da82e79bd to your computer and use it in GitHub Desktop.
ロボホンの画面(背面LCD・プロジェクタ)をPNGでキャプチャします。
#
# 事前準備
# pip install pure-python-adb pillow
#
# 実行方法
# $ adb tcpip 5555
# $ adb connect [ロボホンのIPアドレス]:5555
# ※USBケーブルを抜く
# $ python robohon-capture.py
#
import argparse
import sys
from ppadb.client import Client as AdbClient # v0.2.1-devからadbがppadbに名前が変わった
from PIL import Image
parser = argparse.ArgumentParser(description='ロボホンの画面をPNGファイルにキャプチャします')
parser.add_argument('-l', '--list', action='store_true', help='端末のシリアル一覧を表示します')
parser.add_argument('-s', '--serial', help='接続する端末のシリアル')
parser.add_argument('-p', '--projector', action='store_true', help='プロジェクタ画面をキャプチャする')
parser.add_argument('-1', '--first', action='store_true', default=False, help='第1世代のロボホンの画面をキャプチャする')
parser.add_argument('filename', default='capture.png', nargs='?', help='PNGファイル名')
args = parser.parse_args()
client = AdbClient(host='127.0.0.1', port=5037)
if args.list:
for s in client.devices():
print(s.serial);
sys.exit(0)
if args.serial is None and len(client.devices()) > 0:
args.serial = client.devices()[0].serial
device = client.device(args.serial)
print('端末{}の画面を{}にキャプチャしています...'.format(args.serial, args.filename))
cap = device.screencap()
with open(args.filename, 'wb') as fp:
fp.write(cap)
with Image.open(args.filename) as im:
if args.first:
if args.projector:
im = im.rotate(180, expand=True, resample=Image.Resampling.BICUBIC)
else:
im = im.rotate(-90, expand=True, resample=Image.Resampling.BICUBIC).crop((0, 0, 720, 960))
im.save(args.filename, quality=100)
print('完了しました')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment