码迷,mamicode.com
首页 > 其他好文 > 详细

反向投影的工作原理

时间:2015-06-14 10:53:03      阅读:658      评论:0      收藏:0      [点我收藏+]

标签:

1.反向投影的作用是什么?
    反向投影用于在输入图像(通常较大)中查找特定图像(通常较小或者仅1个像素,以下将其称为模板图像)最匹配的点或者区域,也就是定位模板图像出现在输入图像的位置。
2.反向投影工作原理
    查找的方式就是不断的在输入图像中切割跟模板图像大小一致的图像块,并用直方图对比的方式与模板图像进行比较。

例如我们有一张100x100的输入图像,有一张10x10的模板图像,查找的过程是这样的:
(1)从输入图像的左上角(0,0)开始,切割一块(0,0)至(10,10)的临时图像;
(2)生成临时图像的直方图;
(3)用临时图像的直方图和模板图像的直方图对比,对比结果记为c;
(4)直方图对比结果c,就是结果图像(0,0)处的像素值;
(5)切割输入图像从(0,1)至(10,11)的临时图像,对比直方图,并记录到结果图像;
(6)重复(1)~(5)步直到输入图像的右下角。

calcBackProject

Calculates the back projection of a histogram.
C++: void calcBackProject(const Mat* arrays, int narrays, const int* channels, InputArray hist, OutputArray
backProject, const float** ranges, double scale=1, bool uniform=
true )
C++: void calcBackProject(const Mat* arrays, int narrays, const int* channels, const SparseMat& hist,
OutputArray backProject, const float** ranges, double scale=1, bool uniform=
true )
Python: cv2.calcBackProject(images, channels, hist, ranges[, dst[, scale ]]) !dst
C: void cvCalcBackProject(IplImage** image, CvArr* backProject, const CvHistogram* hist)
Python: cv.CalcBackProject(image, backProject, hist) !None
Parameters

Mat 类型
arrays – Source arrays. They all should have the same depth, CV_8U or CV_32F , and the
same size. Each of them can have an arbitrary number of channels.


narrays – Number of source arrays.


channels – The list of channels used to compute the back projection. The number of
channels must match the histogram dimensionality. The first array channels are numerated
from 0 to arrays[0].channels()-1 , the second array channels are counted from
arrays[0].channels() to arrays[0].channels() + arrays[1].channels()-1, and
so on.


hist – Input histogram that can be dense or sparse.


backProject – Destination back projection aray that is a single-channel array of the same
size and depth as arrays[0] .

ranges – Array of arrays of the histogram bin boundaries in each dimension. See calcHist() .

scale – Optional scale factor for the output back projection.

//是否归一化
uniform – Flag indicating whether the histogram is uniform or not (see above).


The functions calcBackProject calculate the back project of the histogram. That is, similarly to calcHist , at
each location (x, y) the function collects the values from the selected channels in the input images and finds the
corresponding histogram bin. But instead of incrementing it, the function reads the bin value, scales it by scale ,
and stores in backProject(x,y) . In terms of statistics, the function computes probability of each element value in
respect with the empirical probability distribution represented by the histogram. See how, for example, you can find
and track a bright-colored object in a scene:
1. Before tracking, show the object to the camera so that it covers almost the whole frame. Calculate a hue
histogram. The histogram may have strong maximums, corresponding to the dominant colors in the object.
2. When tracking, calculate a back projection of a hue plane of each input video frame using that pre-computed
histogram. Threshold the back projection to suppress weak colors. It may also make sense to suppress pixels
with non-sufficient color saturation and too dark or too bright pixels.
3. Find connected components in the resulting picture and choose, for example, the largest component.
This is an approximate algorithm of the CamShift() color object tracker.

反向投影的工作原理

标签:

原文地址:http://www.cnblogs.com/haoxing990/p/4574722.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!