1、opencv中HOG源码中出现的一些关键字,CV_WRAP and CV_EXPORTS_W
struct CV_EXPORTS_W HOGDescriptor { public: enum { L2Hys=0 }; enum { DEFAULT_NLEVELS=64 };
CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true),
nlevels(HOGDescriptor::DEFAULT_NLEVELS)
{}
这是一个网友的回答
CV_EXPORTS_W is defined inmodules/core/include/opencv2/core/types_c.h as alias for CV_EXPORTS, CV_EXPORTSis defined as:
#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
# define CV_EXPORTS __declspec(dllexport)
#else
# define CV_EXPORTS
#endif
So it's alias for __declspec(dllexport) on Windows platform where CVAPI_EXPORTS is defined, otherwise it's empty.
CV_WARP is used as flag for scripts to create wrappers of the function or method. It is used for creation Python or Java wrappers.
大体意思是说,CV_WARP是一种函数或者方法的封装类,而CVAPI_EXPORTS _W是CVAPI_EXPORTS 的别称,CVAPI_EXPORTS 又是__declspec(dllexport) 的一个别称,
使用 __declspec(dllexport) 关键字从 DLL 导出数据、函数、类或类成员函数。(http://msdn.microsoft.com/zh-cn/library/a90k134d(v=vs.80).aspx)
2、openCv中的一个函数:
int cvRound (double value)
对一个double型的数进行四舍五入,并返回一个整型数!
函数 cvRound, cvFloor, cvCeil 用一种舍入方法将输入浮点数转换成整数。 cvRound 返回和参数最接近的整数值。 cvFloor 返回不大于参数的最大整数值。
cvCeil 返回不小于参数的最小整数值。
3、从现在开始我们要看一些TBB里更实在的一些东西了,之所以说它实在,是因为这些内容是切实地能帮助我们去解决一些并行编程里的问题。
首先看的也是最简单的parallel_for。
我们还是先从一个例子开始看起:
问题:对一个数组里的每个元素施加一个操作Foo(...)
串行化的版本:
1 void SerialApplyFoo (int a[], size_t n) {
2 for (size_t i = 0; i < n; ++ i)
3 Foo(a[i]);
4 }
使用TBB并行化的版本:
1 #include "tbb/task_scheduler_init.h"
2 #include "tbb/blocked_range.h"
3 #include "tbb/parallel_for.h"
4
5 using namespace tbb;
6
7 // 对每个元素执行该操作
8 void Foo(int value)
9 {
10 // Applied function
11 }
12
13 class ApplyFoo
14 {
15 int * const my_a;
16 public:
17 void operator () (const blocked_range<size_t> & r) const
18 {
19 int * a = my_a;
20 for (size_t i = r.begin(); i != r.end(); ++ i)
21 Foo(a[i]);
22 }
23
24 ApplyFoo(int a[]) : my_a(a) {}
25 };
26
27 int main(int argc, char* argv[])
28 {
29 // 创建task scheduler
30 task_scheduler_init init;
31 const int n = 100;
32 int a[n];
33 for (int i = 0; i < n; i ++)
34 a[i] = i;
35 // TBB会把数组分成若干的block
36 // 对block调用ApplyFoo这个functor
37 parallel_for(blocked_range<size_t>(0, n), ApplyFoo(a), simple_partitioner());
38 return 0;
39 }
这个其实就是我们最早开始看TBB时的一个例子。
我们看到这里面多了好几个陌生的东西:
blocked_range
parallel_for
block
OK,我们一个个来看,先说blocked_range,这个template class表述了一个一维迭代(iterator)。同样的,我们先来看看它的declaration(部分无关代码已裁减),在tbb/blocked_range.h里:
#ifndef __TBB_blocked_range_H
#define __TBB_blocked_range_H
#include "tbb_stddef.h"
namespace tbb {
/** \page range_req Requirements on range concept
Class \c R implementing the concept of range must define:
- \code R::R( const R& ); \endcode Copy constructor
- \code R::~R(); \endcode Destructor