9 DGM_ASSERT_MSG(nBins < CV_CN_MAX,
"Number of bins (%d) exceeds the maximum allowed number (%d)", nBins, CV_CN_MAX);
14 int height = img.rows;
18 if (img.channels() != 1) cvtColor(img, I, cv::ColorConversionCodes::COLOR_RGB2GRAY);
26 vec_mat_t vTemp(nBins);
27 vec_mat_t vBins(nBins);
28 vec_mat_t vInts(nBins);
30 for (i = 0; i < nBins; i++) {
31 vTemp[i].create(img.size(), CV_8UC1);
32 vBins[i].create(img.size(), CV_32FC1);
36 std::vector<float *> pBins(nBins);
37 std::vector<double *> pInts0(nBins);
38 std::vector<double *> pInts1(nBins);
39 std::vector<byte *> pTemp(nBins);
42 for (y = 0; y < height; y++) {
43 float *pIx = Ix.ptr<
float>(y);
44 float *pIy = Iy.ptr<
float>(y);
45 for (i = 0; i < nBins; i++) pBins[i] = vBins[i].ptr<float>(y);
46 for (x = 0; x < width; x++) {
51 float gMgn = sqrtf(ix*ix + iy*iy);
54 if (fabs(ix) < FLT_EPSILON) ix = SIGN(ix) * FLT_EPSILON;
56 float gOrt = (0.5f + atanf(tg) / (float)Pi) * 180.0f;
59 float gOrtStep = 180.0f / nBins;
60 for (i = 0; i < nBins; i++)
61 if (gOrt <= (i + 1) * gOrtStep) {
69 for (i = 0; i < nBins; i++) integral(vBins[i], vInts[i]);
71 for (y = 0; y < height; y++) {
73 int y1 = MIN(y + nbhd.
lowerGap, height - 1);
74 for (i = 0; i < nBins; i++) pInts0[i] = vInts[i].ptr<double>(y0);
75 for (i = 0; i < nBins; i++) pInts1[i] = vInts[i].ptr<double>(y1 + 1);
76 for (i = 0; i < nBins; i++) pTemp[i] = vTemp[i].ptr<byte>(y);
77 for (x = 0; x < width; x++) {
78 int x0 = MAX(0, x - nbhd.
leftGap);
79 int x1 = MIN(x + nbhd.
rightGap, width - 1);
81 Mat HOGcell(cv::Size(nBins, 1), CV_64FC1);
82 double *pHOGcell = HOGcell.ptr<
double>(0);
83 for (i = 0; i < nBins; i++) pHOGcell[i] = pInts1[i][x1 + 1] - pInts1[i][x0] - pInts0[i][x1 + 1] + pInts0[i][x0];
84 normalize(HOGcell, HOGcell, 255, 0, cv::NormTypes::NORM_MINMAX);
85 for (i = 0; i < nBins; i++) pTemp[i][x] = static_cast<byte>(pHOGcell[i]);
int rightGap
Distance from the base point to the neighborhood's right boundary.
int leftGap
Distance from the base point to the neighborhood's left boundary.
int lowerGap
Distance from the base point to the neighborhood's lower boundary.
int upperGap
Distance from the base point to the neighborhood's upper boundary.
virtual Mat get(void) const
Extracts and returns the required feature.
Square neighborhood structure.
static Mat getDerivativeY(const Mat &img)
static Mat getDerivativeX(const Mat &img)