Connect PC to Phone camera over HTTP protocol

Rahul Dangi
2 min readJun 10, 2019

--

In this post, we will read about how to display mobile camera input in our PC over HTTP protocol and further read camera input using Python CV2.

Many of you would have used a USB camera, Very Easy! Right, but what if you don't have one. No worries, please read this post and you can do whatever a USB camera does by just using a mobile camera.

  1. Connect your PC and mobile to the same network
  2. Install DroidCam application in your phone
  3. Start DroidCam and you will see the following window as in Image(1)
Image(1)

4. Open the browser and type <Protocol://IP:Port>, here that is http://10.208.23.3:4746/ and you will see the mobile camera displayed in the browser

Next, let's read camera input using a Python script and CV2 module:

  1. Close the browser camera window and rerun DroidCam app
  2. Install Python-CV2 module: pip install opencv-python
  3. Open Python IDE and run below script
import cv2

stream = cv2.VideoCapture('http://10.208.23.3:4746/video')

# Use the next line if your camera has a username and password
# stream=cv2.VideoCapture('protocol://username:password@IP:port/1')

while True:
r, f = stream.read()
print(r,f)
cv2.imshow('IP Camera stream',f)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cv2.destroyAllWindows()

Done, you will see the following output.

Please reach out for any queries. Thanks! for reading.

--

--

Rahul Dangi
Rahul Dangi

Written by Rahul Dangi

Practice Machine Learning | Alumnus-IIT Delhi | www.rahuldangi.ml

No responses yet