当前位置: 首页>>代码示例>>C++>>正文


C++ CFloatImage::ClearPixels方法代码示例

本文整理汇总了C++中CFloatImage::ClearPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ CFloatImage::ClearPixels方法的具体用法?C++ CFloatImage::ClearPixels怎么用?C++ CFloatImage::ClearPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFloatImage的用法示例。


在下文中一共展示了CFloatImage::ClearPixels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
SupportVectorMachine::predictSlidingWindow(const Feature &feat, CFloatImage &response) const
{
    response.ReAllocate(CShape(feat.Shape().width, feat.Shape().height, 1));
    response.ClearPixels();

    /******** BEGIN TODO ********/
    // Sliding window prediction.
    //
    // In this project we are using a linear SVM. This means that
    // it's classification function is very simple, consisting of a
    // dot product of the feature vector with a set of weights learned
    // during training, followed by a subtraction of a bias term
    //
    //          pred <- dot(feat, weights) - bias term
    //
    // Now this is very simple to compute when we are dealing with
    // cropped images, our computed features have the same dimensions
    // as the SVM weights. Things get a little more tricky when you
    // want to evaluate this function over all possible subwindows of
    // a larger feature, one that we would get by running our feature
    // extraction on an entire image.
    //
    // Here you will evaluate the above expression by breaking
    // the dot product into a series of convolutions (remember that
    // a convolution can be though of as a point wise dot product with
    // the convolution kernel), each one with a different band.
    //
    // Convolve each band of the SVM weights with the corresponding
    // band in feat, and add the resulting score image. The final
    // step is to subtract the SVM bias term given by this->getBiasTerm().
    //
    // Hint: you might need to set the origin for the convolution kernel
    // in order to get the result from convoltion to be correctly centered
    //
    // Useful functions:
    // Convolve, BandSelect, this->getWeights(), this->getBiasTerm()

Feature weights = this->getWeights();
	int nWtBands = weights.Shape().nBands;
	
	// Set the center of the window as the origin for the conv. kernel
	for (int band = 0; band < nWtBands; band++)
	{
		// Select a band
		CFloatImage featBand;
		CFloatImage weightBand;
		BandSelect(feat, featBand, band, 0);
		BandSelect(weights, weightBand, band, 0);

		// Set the origin of the kernel
		weightBand.origin[0] = weights.Shape().width / 2;
		weightBand.origin[1] = weights.Shape().height / 2;
		
		// Compute the dot product
		CFloatImage dotproduct;
		dotproduct.ClearPixels();
		Convolve(featBand, dotproduct, weightBand);

		// Add the resulting score image
		for (int y = 0; y < feat.Shape().height; y++)
		{
			for (int x = 0; x < feat.Shape().width; x++)
			{
				response.Pixel(x, y, 0) += dotproduct.Pixel(x, y, 0);
			}
			// End of x loop
		}
		// End of y loop
	}
	// End of band loop
	
	// Substract the SVM bias term
	for (int y = 0; y < feat.Shape().height; y++)
	{
		for (int x = 0; x < feat.Shape().width; x++)
		{
			response.Pixel(x, y, 0) -= this->getBiasTerm();
		}
		// End of x loop
	}
	// End of y loop

    /******** END TODO ********/
}
开发者ID:Sachin003,项目名称:PedestrianDetection,代码行数:85,代码来源:SupportVectorMachine.cpp


注:本文中的CFloatImage::ClearPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。