Tuesday, January 16, 2018

4. Reading Video File or Video Stream over a network using Opencv

In this post we will be learning how to read video file and process it frame by frame. how to acess your webcam or usb webcam using opencv.


What you'll require?

1. imutils package
2. USB camera or IP camera


I am assuming you have conda installed in your system and conda path is configured.
if not then follow on older posts or you can check my blog archives from right side of the page or very below if you are on mobile device.


To install imutils package use the following command.

1. conda install -c anaconda pip


once first command is completed proceed to 2nd.

2. pip install imutils


Once you install imutils we are ready to do our programming.



Make a new File namely video_process.py
and import following modules to our new file.






Important thing to learn here is that when you import any package like cv2 it becomes an object or a variable in your program from which you can access the methods and properties.

Here imutils is one module, module includes video as a class and VideoStream is our object.
we are also importing main imutils class to have access to simple image manipulation. which we will see very soon.


now that we are ready lets open a video stream from any source.

source can be different, below image shows examples.





You can chose any source to open your video. i'll be using src=0 my local leptop webcam.
  • In many cases multiple camera is connected so the src=0 can be changed to 1 or 2 depending on number of cameras connected as same time, by default 0 works in all condition.

now we need a logic to grabs frame from our video source

we will be using while loop here.




Notice that i have commented other two capture variable lines, because i'll be using src=0 only.


Run this program and you will see your VideoStream of your leptop webcam.





Happy coding.


Practice : Try opening any .mp4 or .avi file.





tags: imutils,opencv,python,python opencv, imutls opencv, videostream, read video stream opencv, capture video stream opencv, stream video opencv.




1 comment:

  1. Glad you liked the blog narayana, please do check after sometime i'll update the blog content very soon.

    ReplyDelete