Last active
March 30, 2025 20:56
-
-
Save rish-0-0/322e4b1d1367b45614e3151c5a822f36 to your computer and use it in GitHub Desktop.
For streaming your android phone's primary camera and reading the stream in OpenCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# conda create -n env python=3.6 | |
# pip install opencv-python # this is important because you need ffmpeg enabled | |
import cv2 | |
import numpy as np | |
import time | |
import os | |
# For UDP Speed instead of default TCP | |
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp" | |
my_android_phone = "rtsp://192.168.0.100:8080/h264_pcm.sdp" | |
vcap = cv2.VideoCapture(my_android_phone) | |
def run(cap): | |
while True: | |
ret, frame = cap.read() | |
if not ret: | |
print("Frame is empty") | |
time.sleep(0.5) | |
continue | |
cv2.imshow('VIDEO', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
if __name__ == "__main__": | |
run(vcap) | |
vcap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot to mention. Please install the Android app from the play store: IP Webcam.
You can find it here Link