有什么方法可以更快地获取android sceenshot

时间:2020-04-11 08:47:12

标签: python android screenshot

import subprocess
import cv2
import numpy as np
import time

last_time = time.time()
while True:

        process = subprocess.Popen('adb shell screencap -p', shell=True, stdout=subprocess.PIPE)
        screenshot = process.stdout.read()
        # binary_screenshot = screenshot.replace(b'\r\n', b'\n')
        # print(binary_screenshot)
        img_screenshot = cv2.imdecode(np.frombuffer(screenshot, np.uint8), cv2.IMREAD_COLOR)
        #print(img_screenshot)
        cv2.imshow('image', img_screenshot)
        print('Loop took {} seconds'.format(time.time()-last_time))
        last_time = time.time()
        if cv2.waitKey(25) & 0xFF == ord('q'):
        # cv2.waitKey(0)
          cv2.destroyAllWindows()
          break

这花费很多时间:

Loop took 0.7842843532562256 seconds
Loop took 0.7843461036682129 seconds
Loop took 0.7871546745300293 seconds
Loop took 0.7760162353515625 seconds
Loop took 0.7812981605529785 seconds
Loop took 0.7817659378051758 seconds
Loop took 0.7733104228973389 seconds
Loop took 0.7739517688751221 seconds
Loop took 0.7730555534362793 seconds

0 个答案:

没有答案