Streaming DroidCam video to OpenCV Python in ANYWAY possible
Asked Answered
T

10

11

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

Tibbetts answered 19/3, 2016 at 13:36 Comment(1)
This github repo was quite helpful to me: github.com/ravirajsinh45/… Concretely, the jupyter exampleAndris
A
16

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

Alessi answered 3/7, 2018 at 10:41 Comment(0)
O
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.

Oligoclase answered 26/2, 2022 at 6:19 Comment(1)
Note: droidcam app should be active in your phone.Oligoclase
C
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')

Carrel answered 27/6, 2017 at 20:46 Comment(0)
C
0

Try IP Webcam android app

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

Correspondence answered 19/8, 2016 at 13:57 Comment(0)
M
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)

Miles answered 4/10, 2017 at 21:16 Comment(0)
M
0
cap=cv2.Videocapture(0)
i=0
while(i<50):
    ret,frame=cap.read() //change car -> cap
    print ret
Masquer answered 18/7, 2018 at 5:26 Comment(0)
P
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)
Potsherd answered 28/3, 2019 at 2:18 Comment(0)
F
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()
Faradic answered 27/7, 2020 at 6:12 Comment(0)
H
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()
Hellish answered 18/7, 2021 at 15:42 Comment(0)
D
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)
Deannedeans answered 24/1, 2022 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.