编号函数,求 11+21+3!+・・+K!的和。
时间: 2023-09-12 17:05:43 浏览: 89
Java求1+2!+3!+...+20!的和的代码
5星 · 资源好评率100%
.octave);
int x = keyPoint.x / w;
int y = keyPoint.y / w;
double theta = 2 * Math.PI - keyPoint.angle;
double cosTheta = Math.cos(theta);
double sinTheta = Math.sin(theta);
for (int j = -WINDOW_SIZE; j <= WINDOW_SIZE; j++) {
for (int k = -WINDOW_SIZE; k <= WINDOW_SIZE; k++) {
int x2 = (int) Math.round(x + j * cosTheta + k * sinTheta);
int y2 = (int) Math.round(y - j * sinTheta + k * cosTheta);
if (x2 < 0 || x2 >= width / w || y2 < 0 || y2 >= height / w) {
continue;
}
double dx = (scalespace[keyPoint.octave][keyPoint.interval][y2 * width / w + x2 + 1] - scalespace[keyPoint.octave][keyPoint.interval][y2 * width / w + x2 - 1]) / 2.0;
double dy = (scalespace[keyPoint.octave][keyPoint.interval][(y2 + 1) * width / w + x2] - scalespace[keyPoint.octave][keyPoint.interval][(y2 - 1) * width / w + x2]) / 2.0;
double mag = Math.sqrt(dx * dx + dy * dy);
double angle = Math.atan2(dy, dx);
int bin = (int) Math.floor((angle + Math.PI) * 8.0 / Math.PI);
vec[(j + WINDOW_SIZE) * (WINDOW_SIZE * 2 + 1) + k + WINDOW_SIZE] += mag * gaussian(j, 0) * gaussian(k, 0) * gaussian(bin, 0);
}
}
double norm = 0.0;
for (int j = 0; j < DESC_LENGTH; j++) {
norm += vec[j] * vec[j];
}
norm = Math.sqrt(norm);
for (int j = 0; j < DESC_LENGTH; j++) {
vec[j] /= norm;
}
for (int j = 0; j < DESC_LENGTH; j++) {
descriptors.add(vec[j]);
}
}
return descriptors;
}
private static double gaussian(double x, double sigma) {
return Math.exp(-x * x / (2 * sigma * sigma)) / (sigma * Math.sqrt(2 * Math.PI));
}
private static class KeyPoint {
int x;
int y;
int octave;
int interval;
double value;
double angle;
KeyPoint(int x, int y, int octave, int interval, double value) {
this.x = x;
this.y = y;
this.octave = octave;
this.interval = interval;
this.value = value;
this.angle = calculateAngle();
}
private double calculateAngle() {
int w = (int) Math.pow(2, octave);
int x = this.x / w;
int y = this.y / w;
double dx = (dog[octave][interval][(y + 1) * WINDOW_SIZE + x] - dog[octave][interval][(y - 1) * WINDOW_SIZE + x]) / 2.0;
double dy = (dog[octave][interval][y * WINDOW_SIZE + x + 1] - dog[octave][interval][y * WINDOW_SIZE + x - 1]) / 2.0;
return Math.atan2(dy, dx) + Math.PI;
}
}
}
```
该代码实现了SURF算法,并可以从指定的图片中提取特征点描述子。调用 `extractFeatures` 方法即可得到特征点描述子,返回值是一个包含512个元素的List<Double>。
阅读全文