【问题标题】:How to capture android screen using python如何使用python捕获android屏幕
【发布时间】:2019-06-14 13:11:01
【问题描述】:

我想使用 python(使用 opencv 或其他库)对我的 android 屏幕进行一些图像处理。
我是一名 python 程序员,因此不想使用 android studio 或学习其他图像处理工具,只是为了这个特殊的小任务。

如何使用 python over usb/ip/anything 连接我的手机以将其屏幕流式传输到我的计算机?

如果可能的话,我也不介意用 python 编写代码并在 android 上运行它。

【问题讨论】:

    标签: android python


    【解决方案1】:

    试试这个 但是你需要使用这个基本上是IP摄像头的应用程序 https://play.google.com/store/apps/details?id=com.pas.webcam

    # Stream Video with OpenCV from an Android running IP Webcam (https://play.google.com/store/apps/details?id=com.pas.webcam)
    # Code Adopted from http://stackoverflow.com/questions/21702477/how-to-parse-mjpeg-http-stream-from-ip-camera
    
    import cv2
    import urllib2
    import numpy as np
    import sys
    
    host = "192.168.0.220:8080"
    if len(sys.argv)>1:
        host = sys.argv[1]
    
    hoststr = 'http://' + host + '/video'
    print 'Streaming ' + hoststr
    
    stream=urllib2.urlopen(hoststr)
    
    bytes=''
    while True:
        bytes+=stream.read(1024)
        a = bytes.find('\xff\xd8')
        b = bytes.find('\xff\xd9')
        if a!=-1 and b!=-1:
            jpg = bytes[a:b+2]
            bytes= bytes[b+2:]
            i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
            cv2.imshow(hoststr,i)
            if cv2.waitKey(1) ==27:
                exit(0)
    

    【讨论】:

      猜你喜欢
      • 2011-06-06
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多