Connect PC to Phone camera over HTTP protocol
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.
- Connect your PC and mobile to the same network
- Install DroidCam application in your phone
- Start DroidCam and you will see the following window as in 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:
- Close the browser camera window and rerun DroidCam app
- Install Python-CV2 module: pip install opencv-python
- 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.