Ask Your Question
0

how to use IP camera in place of webcam in python ?

asked 2017-04-16 10:35:19 -0500

Arshad gravatar image

updated 2017-04-16 17:50:26 -0500

berak gravatar image

I have been using this logic all the while. I was using standard webcam with cv2 (version 2.4.13)

cam = cv2.VideoCapture(0)
while(True):
    ret,img = cam.read()

But i want to use IP camera in place of webcam. give a lead how to get around with IP camera in openCV+Python

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-04-16 17:50:02 -0500

berak gravatar image

just use your url instead of the camera id, like:

 cam = cv2.VideoCapture('192.168.0.17/my/stream.mjpeg')
edit flag offensive delete link more

Comments

Code :

cam =cv2.VideoCapture('http://192.168.1.4:8080/video')
    while(True):
         ret,img = cam.read();
         gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
          ...

Error :

        Traceback (most recent call last):
          File "C:\Face rocog project\Face recog
sqllite\datasetCreator.py", line 33,
in <module>
            gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        error: ..\..\..\..\opencv\modules\imgproc\src\color.cpp:3739:
error: (-215) scn == 3 || scn == 4
    in function cv::cvtColor

It is working fine with VideoCapture(0) but having this error with ip cam

Arshad gravatar imageArshad ( 2017-04-16 20:58:20 -0500 )edit

ofc. you have to check cam.isOpened() to check, if it could connect., and ret==True to see if you couldread a valid image.

your img is empy / invalid, thus cvtColor complained.

berak gravatar imageberak ( 2017-04-17 00:11:33 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-04-16 10:33:31 -0500

Seen: 17,060 times

Last updated: Apr 16 '17