processing on a live webcam streaming video???

79 views (last 30 days)
Hashem Burki
Hashem Burki on 11 May 2011
Commented: Florian Morsch on 21 Jun 2018
I am using an image acquisition toolbox to obtain the live stream from my webcam. I have my own code for skin color segmentation which works well on pictures (JPEG etc). I am only able to get a snapshot of the live video and then apply the code. I need to apply that code on the live webcam video stream. How can i do it???
  1 Comment
David Tarkowski
David Tarkowski on 11 May 2011
I'm not sure what you mean, a video stream is just a series of snapshots at a specified interval. Can you elaborate on what you are doing and how it differs from what you would like?

Sign in to comment.

Answers (3)

Harsha Vardhan Rao  Avunoori
Well I think you can try using the Image Acquisition ToolBox for your case it will definitely help you...
For more information on Image Acquisition ToolBox have a look at this website

Hashem Burki
Hashem Burki on 25 May 2011
what i ment was that i want to perform a skin segmentation code on an input webcam video, and want to preview it as an output video. how can i do it?
Walter Roberson
Walter Roberson on 20 Jun 2018
"will the output video be as smooth as a live stream"
As we were discussing in, you are using the Automated Driving toolbox. You are limited by the functions in that toolbox that you call. This is probably not an issue of the webcam interface being slow: this is quite likely an issue that you are doing extensive computation with each frame.
No computer can respond instantly. If you want a frame to be ready to output within 1/30 of a second so that you can get 30 fps output, then you need to restrict yourself to computations that that computer can finish within 1/30 of a second. It does not matter whether the camera interface takes 30 microseconds per frame or 30 milliseconds per frame (33 1/3 fps) if the computation you are doing takes (say) 1/4 second. That is true whether that (say) 1/4 second per frame is because you are using slow hardware; or because you are trying to use more RAM than you have available and the program is swapping; or because you wrote inefficient code such as failing to pre-initialize arrays that you are storing into; or because you are just plain trying to compute things more complex than current computer speeds could reasonably get done in that length of time.
The Automated Driving Toolbox is a premium toolbox; very few of the regular volunteers here have access to even the documentation for it, so it is difficult for us to make suggestions (especially since you do not include any code.)

Sign in to comment.

Florian Morsch
Florian Morsch on 15 Jun 2018
Edited: Florian Morsch on 15 Jun 2018
You way to do it would be:
1: Create a webcam object EDIT: or create a cam object
2: You can get screenshots/snapshots from the object
3: Create a videoplayer object
4: Now you run a while loop and take a snapshot, process it and give it to the videoPlayer as output, which can step through the frames he gets. The FPS is limited to your code, if you need 1 second to work with a frame then you will get 1 FPS, if your code is fast enough you might end up with 10-15 FPS or more.
Now its up to you how fast your code works to get a smoother "video". RealTime is mostly not possible since you need to do some operations on the frame which means you have processing time (except your code is really really good and you can manage to do the processing in like under 20ms, which would be 50 FPS).
Florian Morsch
Florian Morsch on 21 Jun 2018
Refering to your comment: You could store the frames and then analyse every frame, but that would be video processing, not real time processing, if you code is not fast enough for real time in the first place. That would be like taking a video, process every frame and then rewatch it. Sure, you would get no "lag" like in the stream processing, but its not real time anymore, its a video you watch.
Some things can help you to make the code faster (preallocating can reduce the processing time by a lot) see:

Sign in to comment.


Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!