Winter 2018 MecE 467 (Modeling and Simulation of Engineering Systems) final project. The objective of the following project was to create a MATLAB program that has the ability to detect, track, and recognize an object using a webcam. The program was to run in real time and in a variety of different settings. How to find the orientation of 2D object using. Learn more about webcam, machine vision, image processing, image acquisition, principle axis, orientation, 2d, computer vision, reference axis, robotic arm. Get started using USB webcams with MATLAB Online™. Set up a USB webcam in your web browser and discover the different features MATLAB Online offers for USB webcams. Perform basic tasks such as taking single images and video. Implement an object classifier using a deep learning neural network to classify everyday objects using the USB webcam.
This example shows how to automatically detect and track a face in a live video stream, using the KLT algorithm.
Overview
Object detection and tracking are important in many computer vision applications including activity recognition, automotive safety, and surveillance. In this example you will develop a simple system for tracking a single face in a live video stream captured by a webcam. MATLAB provides webcam support through a Hardware Support Package, which you will need to download and install in order to run this example. The support package is available via the Support Package Installer.
The face tracking system in this example can be in one of two modes: detection or tracking. In the detection mode you can use a vision.CascadeObjectDetector
object to detect a face in the current frame. If a face is detected, then you must detect corner points on the face, initialize a vision.PointTracker
object, and then switch to the tracking mode.
In the tracking mode, you must track the points using the point tracker. As you track the points, some of them will be lost because of occlusion. If the number of points being tracked falls below a threshold, that means that the face is no longer being tracked. You must then switch back to the detection mode to try to re-acquire the face.
Setup
Create objects for detecting faces, tracking points, acquiring and displaying video frames.
Detection and Tracking
Capture and process video frames from the webcam in a loop to detect and track a face. The loop will run for 400 frames or until the video player window is closed.
References
Viola, Paul A. and Jones, Michael J. 'Rapid Object Detection using a Boosted Cascade of Simple Features', IEEE CVPR, 2001.
Bruce D. Lucas and Takeo Kanade. An Iterative Image Registration Technique with an Application to Stereo Vision. International Joint Conference on Artificial Intelligence, 1981.
Carlo Tomasi and Takeo Kanade. Detection and Tracking of Point Features. Carnegie Mellon University Technical Report CMU-CS-91-132, 1991.
Jianbo Shi and Carlo Tomasi. Good Features to Track. IEEE Conference on Computer Vision and Pattern Recognition, 1994.
Object Tracking In Matlab Using Webcam Captures
Zdenek Kalal, Krystian Mikolajczyk and Jiri Matas. Forward-Backward Error: Automatic Detection of Tracking Failures. International Conference on Pattern Recognition, 2010
Create a Webcam Object
To acquire images from a webcam, you first create a webcam object. Use the webcam
function to create the object. You can use it in three ways:
Connect to the first or only camera by using no input arguments
Specify a camera by name by using the webcam name (as a character vector) in an input argument
Specify a camera by the list order using an index number as the input argument
Note
In desktop versions of MATLAB®, webcam support is available through the MATLAB Support Package for USB Webcams. For instructions, see Install the MATLAB Support Package for USB Webcams. Webcams are also supported in MATLAB Online™. For more information, see Webcam Support in MATLAB Online.
Find the name of your camera by using the webcamlist
function. Run webcamlist
first to make sure that MATLAB can discover your camera(s). In this example, it discovers the built-in webcam in the Dell® computer, and a connected Logitech® webcam.
No Input Argument
If you use the webcam
function with no input argument, it creates the object and connects to the first camera returned by webcamlist
. In this case, it uses the Logitech camera, since that appears in the list first.
When you create the webcam
object, it connects to the camera, establishes exclusive access, and starts streaming data. You can then preview the data and acquire images using the snapshot
function, as described in Acquire Webcam Images.
Matlab Object Tracking Using Webcam
Note
The only properties available in MATLAB Online are Name
, AvailableResolutions
, and Resolution
. The default resolution of the webcam is the only resolution supported in MATLAB Online for the R2018a release.
Index as Input Argument
If you use the webcam
function with an index as the input argument, it creates the object corresponding to that index and connects to that camera. If you only have one camera, you do not need to use the index. You can use the webcam
function with no input argument and it creates the object with the single camera that is connected. The index is useful when you have multiple cameras.
The index corresponds to the order of cameras in the cell array returned by webcamlist
when you have multiple cameras connected. In this example, device 1
is the Logitech camera and device 2
is the built-in Dell webcam.
Camera Name as Input Argument
If you use the webcam
function with the name of the camera (as a character vector) as the input argument, it creates the object and connects to the camera with that name. Use the exact name that is displayed by the webcamlist
function, such as 'Logitech Webcam 250'
, or use a shortened version of the name, such as the camera brand. In this case, you can simply use 'Logitech'
to connect to the Logitech webcam.
When you create the webcam
object, it connects to the camera, establishes exclusive access, and starts streaming data. You can then preview the data and acquire images using the snapshot
function, as described in Acquire Webcam Images.