void interp_extremum(int octv, int intvl, int r, int c) { double xi = 0, xr = 0, xc = 0; int step = init_sample * COpenSURF.cvRound(COpenSURF.pow(2.0f, octv)); // Get the offsets to the actual location of the extremum bool bok = interp_step(octv, intvl, r, c, out xi, out xr, out xc); if (bok == false) { return; } // If point is sufficiently close to the actual extremum if (COpenSURF.fabs((float)xi) <= 0.5 && COpenSURF.fabs((float)xr) <= 0.5 && COpenSURF.fabs((float)xc) <= 0.5) { // Create Ipoint and push onto Ipoints vector Ipoint ipt = new Ipoint(); ipt.x = (float)(c + step * xc); ipt.y = (float)(r + step * xr); ipt.scale = (float)((1.2f / 9.0f) * (3 * (COpenSURF.pow(2.0f, octv + 1) * (intvl + xi + 1) + 1))); ipt.laplacian = (int)getLaplacian(octv, intvl, c, r); ipts.Add(ipt); } }
void getUprightDescriptor() { int y, x, count = 0; int scale; float dx, dy, mdx, mdy; float gauss, rx, ry, len = 0.0f; float[] desc; Ipoint ipt = ipts[index]; scale = (int)ipt.scale; y = COpenSURF.cvRound(ipt.y); x = COpenSURF.cvRound(ipt.x); desc = ipt.descriptor; // Calculate descriptor for this interest point for (int i = -10; i < 10; i += 5) { for (int j = -10; j < 10; j += 5) { dx = dy = mdx = mdy = 0; for (int k = i; k < i + 5; ++k) { for (int l = j; l < j + 5; ++l) { // get Gaussian weighted x and y responses gauss = COpenSURF.gaussian(k * scale, l * scale, 3.3f * scale); rx = gauss * haarX(k * scale + y, l * scale + x, 2 * scale); ry = gauss * haarY(k * scale + y, l * scale + x, 2 * scale); dx += rx; dy += ry; mdx += COpenSURF.fabs(rx); mdy += COpenSURF.fabs(ry); } } // add the values to the descriptor vector desc[count++] = dx; desc[count++] = dy; desc[count++] = mdx; desc[count++] = mdy; // store the current length^2 of the vector len += dx * dx + dy * dy + mdx * mdx + mdy * mdy; } } // convert to unit vector len = (float)Math.Sqrt(len); for (int i = 0; i < 64; i++) { desc[i] /= len; } }
float getValLowe(int o, int i, int r, int c) { int index = (o * intervals + i) * (i_width * i_height) + (r * i_width + c); if (m_det == null) { return(0); } if (index < 0 || index >= m_det.Length) { return(0); } return(COpenSURF.fabs(m_det[index])); }
void getIpoint(int o, int i, int c, int r) { //! Interpolate feature to sub pixel accuracy bool converged = false; float[] x = new float[3]; for (int steps = 0; steps <= interp_steps; ++steps) { // perform a step of the interpolation stepInterp(o, i, c, r, x); // check stopping conditions if (COpenSURF.fabs(x[0]) < 0.5 && COpenSURF.fabs(x[1]) < 0.5 && COpenSURF.fabs(x[2]) < 0.5) { converged = true; break; } // find coords of different sample point c += COpenSURF.cvRound(x[0]); r += COpenSURF.cvRound(x[1]); i += COpenSURF.cvRound(x[2]); // check all param are within bounds if (i < 1 || i >= intervals - 1 || c < 1 || r < 1 || c > i_width - 1 || r > i_height - 1) { return; } } // if interpolation has not converged on a result if (!converged) { return; } // create Ipoint and push onto Ipoints vector Ipoint ipt = new Ipoint(); ipt.x = (float)(c + x[0]); ipt.y = (float)(r + x[1]); ipt.scale = (1.2f / 9.0f) * (3 * (COpenSURF.pow(2.0f, o + 1) * (i + x[2] + 1) + 1)); ipt.laplacian = (int)getLaplacian(o, i, c, r); if (ipts == null) { ipts = new List <Ipoint>(); } ipts.Add(ipt); }
void getDescriptor() { int y, x, count = 0; float dx, dy, mdx, mdy, co, si; float[] desc; int scale; int sample_x; int sample_y; float gauss, rx, ry, rrx, rry, len = 0; Ipoint ipt = ipts[index]; scale = (int)ipt.scale; x = COpenSURF.cvRound(ipt.x); y = COpenSURF.cvRound(ipt.y); co = (float)Math.Cos(ipt.orientation); si = (float)Math.Sin(ipt.orientation); desc = ipt.descriptor; // Calculate descriptor for this interest point for (int i = -10; i < 10; i += 5) { for (int j = -10; j < 10; j += 5) { dx = dy = mdx = mdy = 0; for (int k = i; k < i + 5; ++k) { for (int l = j; l < j + 5; ++l) { // Get coords of sample point on the rotated axis sample_x = COpenSURF.cvRound(x + (-l * scale * si + k * scale * co)); sample_y = COpenSURF.cvRound(y + (l * scale * co + k * scale * si)); // Get the gaussian weighted x and y responses gauss = COpenSURF.gaussian(k * scale, l * scale, 3.3f * scale); rx = gauss * haarX(sample_y, sample_x, 2 * scale); ry = gauss * haarY(sample_y, sample_x, 2 * scale); // Get the gaussian weighted x and y responses on rotated axis rrx = -rx * si + ry * co; rry = rx * co + ry * si; dx += rrx; dy += rry; mdx += COpenSURF.fabs(rrx); mdy += COpenSURF.fabs(rry); } } // add the values to the descriptor vector desc[count++] = dx; desc[count++] = dy; desc[count++] = mdx; desc[count++] = mdy; // store the current length^2 of the vector len += dx * dx + dy * dy + mdx * mdx + mdy * mdy; } // for (int j = -10; j < 10; j+=5) } // for (int i = -10; i < 10; i+=5) // convert to unit vector len = (float)Math.Sqrt(len); for (int i = 0; i < 64; i++) { desc[i] /= len; } }
float getVal(int o, int i, int c, int r) { //! Return the value of the approximated determinant of hessian return(COpenSURF.fabs(m_det[(o * intervals + i) * (i_width * i_height) + (r * i_width + c)])); }