Reputation: 111
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
Upvotes: 11
Views: 22370
Reputation: 31
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.
Upvotes: 3
Reputation: 11
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()
Upvotes: 0
Reputation: 661
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)
Upvotes: 0
Reputation: 138
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()
Upvotes: 0
Reputation: 1
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)
Upvotes: 0
Reputation: 1
cap=cv2.Videocapture(0)
i=0
while(i<50):
ret,frame=cap.read() //change car -> cap
print ret
Upvotes: 0
Reputation: 199
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
Upvotes: 16
Reputation: 1
I just used the following instructions and worked for me.
cap = cv2.VideoCapture(0)
Upvotes: 0
Reputation: 1232
Change IP address bellow
cap = cv2.VideoCapture('http://192.168.0.21:4747/mjpegfeed')
Upvotes: 2