initializeSearchWindow
Set initial search window
Description
initializeSearchWindow(
sets the initial search window region,hbtracker
,R
)R
. The tracker uses
this region as the initial window to search for the object. You can also use
this function when the tracker loses track of the object. Use the function to
reinitialize an object's initial location and size.
Examples
Track a Face
Track and display a face in each frame of an input video.
Create System objects for reading and displaying video and for drawing a bounding box of the object.
videoReader = VideoReader('vipcolorsegmentation.avi'); videoPlayer = vision.VideoPlayer(); shapeInserter = vision.ShapeInserter('BorderColor','Custom', ... 'CustomBorderColor',[1 0 0]);
Read the first video frame, which contains the object. Convert the image to HSV color space. Then define and display the object region.
objectFrame = im2single(readFrame(videoReader));
objectHSV = rgb2hsv(objectFrame);
objectRegion = [40, 45, 25, 25];
objectImage = shapeInserter(objectFrame, objectRegion);
figure
imshow(objectImage)
title('Red box shows object region')
(Optionally, you can select the object region using your mouse. The object must occupy the majority of the region. Use the following command.)
figure; imshow(objectFrame); objectRegion=round(getPosition(imrect))
Set the object, based on the hue channel of the first video frame.
tracker = vision.HistogramBasedTracker; initializeObject(tracker, objectHSV(:,:,1) , objectRegion);
Track and display the object in each video frame. The while loop reads each image frame, converts the image to HSV color space, then tracks the object in the hue channel where it is distinct from the background. Finally, the example draws a box around the object and displays the results.
while hasFrame(videoReader) frame = im2single(readFrame(videoReader)); hsv = rgb2hsv(frame); bbox = tracker(hsv(:,:,1)); out = shapeInserter(frame,bbox); videoPlayer(out); end
Release the video player.
release(videoPlayer);
Input Arguments
hbtracker
— Histogram based tracker
vision.HistogramBasedTracker
object
Histogram based tracker, specified as a
vision.HistogramBasedTracker
object.
R
— Initial search window
[x
y
width
height]
Initial search window, specified in the format [x y width height].
Version History
Introduced in R2012a
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)