#include #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include #include #include "HoG.cpp" extern "C" { static PyObject *hogpy_hog(PyObject *self, PyObject *args) { // You code goes here! PyArrayObject* pixels; long nb_bins, cwidth, block_size; long x_dim_l, y_dim_l, stride_l; bool unsigned_dirs, grayscale; double clip_val; if (not PyArg_ParseTuple(args, "O!llllllbdb", &PyArray_Type, &pixels, &x_dim_l, &y_dim_l, &stride_l, &nb_bins, &cwidth, &block_size, &unsigned_dirs, &clip_val, &grayscale) ) { PyErr_Format(PyExc_ValueError, "Failed to parse Arguments"); return NULL; } size_t stride = stride_l; size_t img_size[2]; img_size[0] = x_dim_l; img_size[1] = y_dim_l; size_t num_features = getNumFeatures(img_size, nb_bins, cwidth, block_size); npy_intp out_dims[1]; out_dims[0] = num_features; PyArrayObject* out = (PyArrayObject*)PyArray_SimpleNew(1, out_dims, NPY_DOUBLE); HoG((double*)PyArray_GETPTR1(pixels, 0), nb_bins, cwidth, block_size, unsigned_dirs, clip_val, img_size, stride, (double*)PyArray_GETPTR1(out, 0), grayscale); return PyArray_Return(out); } static PyMethodDef HogpyMethods[] = { {"hog", hogpy_hog, METH_VARARGS, "Compute the HOG feature vector for an image."}, {NULL, NULL, 0, NULL}}; static struct PyModuleDef hogymodule = { PyModuleDef_HEAD_INIT, "hogpy", /* name of module */ NULL, /* module documentation, may be NULL */ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ HogpyMethods}; PyMODINIT_FUNC PyInit_hogpy() { PyObject *m = PyModule_Create(&hogymodule); if (m == nullptr) return nullptr; import_array(); return m; } }