camshift算法(3)

這是一外國人寫的使用示例:

OpenCV's face tracker uses an algorithm called Camshift. Camshift consists of four steps:

  1. Create a color histogram to represent the face
  2. Calculate a "face probability" for each pixel in the incoming video frames
  3. Shift the location of the face rectangle in each video frame
  4. Calculate the size and angle

Here's how each step works:

1. Create a histogram Camshift represents the face it's tracking as a histogram (also called a barchart) of color values. Figure 1 shows two example histograms produced by the Camshift demo program that ships with OpenCV. The height of each colored bar indicates how many pixels in an image region have that "hue." Hue is one of three values describing a pixel's color in the HSV (Hue, Saturation, Value) color model. (For more on color, and color models, and see "The World of Color," SERVOMagazine, November 2005.)

In the image region represented by the top histogram, a bluish hue is most common, and a slightly more lavender hue is the next most common. The bottom histogram shows a region in which the most common hue is the rightmost bin. This hue is almost, but not quite, red.

2. Calculate face probability - simpler than it sounds! The histogram is created only once, at the start of tracking. Afterwards, it's used to assign a "face-probability" value to each image pixel in the video frames that follow.

"Face probability" sounds terribly complicated, and heavily mathematical, but it's neither! Here's how it works. Figure 2 shows the bars from a histogram stacked one atop the other. After stacking them, it's clear that the rightmost bar accounts for about 45% of the pixels in the region. That means the probability that a pixel selected randomly from this region would fall into the rightmost bin is 45%. That's the "face probability" for a pixel with this hue. The same reasoning indicates that the face probability for the next histogram bin to the right is about 20%, since it accounts for about 20% of the stack's total height. That's all there is to it.

 

原文地址:http://www.cnblogs.com/seacode/archive/2010/09/28/1837694.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章