Last active
December 22, 2015 09:09
-
-
Save ahojnnes/6450073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cython: cdivision=True | |
#cython: boundscheck=False | |
#cython: nonecheck=False | |
#cython: wraparound=False | |
cimport numpy as cnp | |
import numpy as np | |
from libc.math cimport sin, cos, M_PI, round | |
def _orb_loop(double[:, ::1] image, Py_ssize_t[:, ::1] keypoints, | |
double[:] orientations, int[:, ::1] pos0, int[:, ::1] pos1): | |
cdef Py_ssize_t i, d, kr, kc, pr0, pr1, pc0, pc1, spr0, spr1, spc0, spc1 | |
cdef double angle | |
cdef char[:, ::1] descriptors = np.zeros((keypoints.shape[0], 256), | |
dtype=np.int8) | |
for i in range(keypoints.shape[0]): | |
angle = orientations[i] | |
sin_a = sin(angle * M_PI / 180.) | |
cos_a = cos(angle * M_PI / 180.) | |
kr = keypoints[i, 0] | |
kc = keypoints[i, 1] | |
for j in range(256): | |
pr0 = pos0[j, 0] | |
pr1 = pos1[j, 0] | |
pc0 = pos0[j, 1] | |
pc1 = pos1[j, 1] | |
spr0 = <Py_ssize_t>round(cos_a * spr0 + sin_a * spc0) | |
spc0 = <Py_ssize_t>round(cos_a * spr0 - sin_a * spc0) | |
spr1 = <Py_ssize_t>round(cos_a * spr1 + sin_a * spc1) | |
spc1 = <Py_ssize_t>round(cos_a * spr1 - sin_a * spc1) | |
if image[kr + pr0, kc + pc0] < image[kr + pr1, kc + pc1]: | |
descriptors[i, j] = True | |
return np.asarray(descriptors) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment