How-to-mirror-your-android-screen-with-opencv icon indicating copy to clipboard operation
How-to-mirror-your-android-screen-with-opencv copied to clipboard

extract the android screen as opencv Mat or numpy array

Open mrnth opened this issue 4 years ago • 6 comments

Hello bro, If you know any open source or python library help extract the android screen as opencv Mat or numpy array, please share it to me. Thank you so much

mrnth avatar Sep 12 '21 17:09 mrnth

Hey @mrnth, This repository does exactly the same, except the codebase is very old.

imneonizer avatar Sep 13 '21 03:09 imneonizer

Hey @mrnth, This repository does exactly the same, except the codebase is very old.

i want to hide all application window when running my python script. So, I can not capture pc screen. but I found a android sw help stream android screen to HTTP then iI can get realtime frame by opencv. it's very useful even though the latency is quite high https://play.google.com/store/apps/details?id=info.dvkr.screenstream&hl=en&gl=US Thanks for your reply

mrnth avatar Sep 13 '21 09:09 mrnth

Wow!! Thanks for sharing the application. Indeed you can capture the screen using OpenCV.

On top of that, if you are facing high latency I would suggest to use USB Debugging + ADB and do port forward via USB for a low latency streaming.

imneonizer avatar Sep 13 '21 11:09 imneonizer

Thanks for the suggestion. I found the command to cast android screen using ffplay on Linux: "adb shell screenrecord --output-format = h264 - | ffplay -framerate 60 -probesize 32 -sync video -" But I don't know how to get frame using opencv in my python script. If you know more information. please give me some keywords or suggestions, thanks a lot

mrnth avatar Sep 14 '21 11:09 mrnth

I will suggest sticking with the screen stream application, You can directly access the stream using opencv by passing the url into VideoCapture object.

Example:

import cv2

device_ip = "192.168.0.44"
cap = cv2.VideoCapture(f"http://{device_ip}:8080/stream.mjpeg")

while True:
    success, frame = cap.read()
    if not success:
        break

    cv2.imshow("frame", frame)
    if cv2.waitKey(1) == ord("q"): 
        break

If you want to cast screen via port forwarding using USB, open the screen stream aplication go to settings>advanced and enable locahost and start streaming. Now connect your device to the system in USB Debugging mode and do a port forwarding

adb forward tcp:8080 tcp:8080

After this, you can visit locahost:8080 to view the screen cast on your system

imneonizer avatar Sep 15 '21 05:09 imneonizer

Thank you so much

mrnth avatar Sep 15 '21 06:09 mrnth