Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access phone camera using python script

I made a simple motion detector program in using python 3.7 and opencv, is there a way to access my phone's camera using python and stream the video to my laptop using bluetooth or mobile hotspot so I can process the data on my laptop? I'm basically just using my phone as a detachable camera.

like image 834
Richard Marin Avatar asked Nov 03 '18 10:11

Richard Marin


People also ask

How do I get Python to access my phone?

First, install the OpenCV library in Python; pip install opencv-python. Download and install the IP Webcam application on your smartphones. After installing the IP Webcam app, make sure your phone and PC are connected to the same network. Run the app on your phone and click Start Server.


1 Answers

Use IP Webcam android application. url is given by ip webcam and at the end I have added video for video streaming or you can url = 'http://192.168.137.138:8080/shot.jpg' inside for loop before cap.read()

This works for me flawlessly with 1280 x 720 resolution NOTE your url ip will change but add video in the last

import cv2 
import numpy as np`
url = 'http://192.168.137.138:8080/video'
cap = cv2.VideoCapture(url)
while(True):
    ret, frame = cap.read()
    if frame is not None:
        cv2.imshow('frame',frame)
    q = cv2.waitKey(1)
    if q == ord("q"):
        break
cv2.destroyAllWindows()
like image 136
Medhavi Monish Avatar answered Oct 23 '22 03:10

Medhavi Monish