10

I currently have the Droid cam Application installed on my android, it is being detected and is streaming on Skype through wifi (Droid Cam client). It is however not streaming to OpenCV, no matter what number I put in for the following.

cap=cv2.VideoCapture()

In addition to this, I have an IP address, so is there any way I can implement this so that OpenCV can read an process images wireless from my camera? I know that it does not even begin to read the camera as I have tested it with the following code, which returns FALSE every time I run it.

cap=cv2.Videocapture(0) #Use default cam
i=0
while(i<50):
    ret,frame=cap.read()
    print ret

Keeps returning false, meaning camera isn't being recognized :L

Fwinter1
  • 92
  • 1
  • 1
  • 8
DhruvK
  • 101
  • 1
  • 1
  • 3
  • This github repo was quite helpful to me: https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python Concretely, the [jupyter example](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/using_USB/camera_input_from_Android.ipynb) – Javier TG May 06 '21 at 17:42

10 Answers10

15

You have to enter the ip address of the droidcam followed by the format.The following method worked flawlessly for me : cap = cv2.VideoCapture('http://0.0.0.0:4747/mjpegfeed?640x480')

Make sure you open the client and do not access the camera feed elsewhere

Manoj Guha
  • 189
  • 1
  • 4
3

Its simple, droidcam app shows the url; just copy it and paste in the videocapture.

IP Cam Access:
http://192.168.29.201:4747/video

Paste the url like this :

import cv2

cap = cv2.VideoCapture('http://192.168.29.201:4747/video')

while True:
    ret, frame = cap.read()

    cv2.imshow("frame", frame)
    cv2.waitKey(1)

Thats it. Opencv should take the feed from your droidcam.

2
  • Install Droid Cam
  • Enable USB Debugging
  • Connected camera via USB to your computer
  • Change IP address bellow

    cap = cv2.VideoCapture('http://192.168.0.21:4747/mjpegfeed')

Barmaley
  • 1,232
  • 20
  • 27
0

Try IP Webcam android app

and get frames from http://your-ip:8080/shot.jpg?

Alfa
  • 599
  • 6
  • 22
0

I just used the following instructions and worked for me.

  1. Install Droidcam;
  2. Enable USB Debugging
  3. Connected camera via USB to your computer
  4. Use the code:

cap = cv2.VideoCapture(0)

0
cap=cv2.Videocapture(0)
i=0
while(i<50):
    ret,frame=cap.read() //change car -> cap
    print ret
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
0
i=0
while(i<50):
    #put this statement inside the loop to capture the frame returned by ip webcam or 
    #droidcam in every iteration
    #put image address in the parameter
    cap=cv2.VideoCapture('http://192.168.x.x:4747/shot.jpg?rnd=890215') 
    ret,frame=car.read()
    print(ret)
Fwinter1
  • 92
  • 1
  • 1
  • 8
0

This answer here worked for me, replacing the url with http://my-ip:8080/shot.jpg for IP Webcam app. Here is my code:

import cv2
import urllib.request
import numpy as np

my_ip = # ip given by ip-webcam

while True:
    req = urllib.request.urlopen('http://'+my_ip+':8080/shot.jpg')
    arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
    img = cv2.imdecode(arr, -1) # 'Load it as it is'

    if cv2.waitKey(1) == 27:
        break
    cv2.imshow('Its Me', img)

cv2.destroyAllWindows()
Shivam
  • 11
  • 2
0

here is the python code to do wirelessly stream video from android to opencv through droidcam

import numpy as np
import cv2

#go to the setting find ip cam username and password if it is not empty use 
#first one
#cap = cv2.VideoCapture('http://username:password@ip:port/video')
cap = cv2.VideoCapture('http://ip:port/video')


while(cap.isOpened()):
    ret, frame = cap.read()

    #do some stuff
    gray  = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
Aniket singh
  • 118
  • 1
  • 6
0

Install droidcam app on PC and mobile and then write this code:

import cv2

cap =cv2.VideoCapture(1)

while True:
    _, img = cap.read()

    cv2.imshow("img", img)
    cv2.waitKey(1)
Tanay
  • 561
  • 1
  • 3
  • 16