Есть ли способы получить android Scenenshot гораздо быстрее - PullRequest
0 голосов
/ 11 апреля 2020
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
...