PageRenderTime 301ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/training/features/calcsurf.cpp

https://github.com/makerere-compute/ocula
C++ | 67 lines | 42 code | 9 blank | 16 comment | 1 complexity | 89d058d54be959ee7ae84265b44ef535 MD5 | raw file
  1. /*
  2. Calculate SURF descriptor for a single, specified keypoint
  3. Compile with:
  4. g++ `pkg-config --cflags opencv` -lopencv_core -lopencv_features2d -o calcsurf calcsurf.cpp
  5. */
  6. #include <opencv2/objdetect/objdetect.hpp>
  7. #include <opencv2/features2d/features2d.hpp>
  8. #include <opencv2/highgui/highgui.hpp>
  9. #include <opencv2/calib3d/calib3d.hpp>
  10. #include <opencv2/imgproc/imgproc_c.h>
  11. #include <iostream>
  12. #include <vector>
  13. int main(int argc, char** argv)
  14. {
  15. const char* filename = argv[1];
  16. int x;
  17. int y;
  18. int size;
  19. sscanf(argv[2], "%d", &x);
  20. sscanf(argv[3], "%d", &y);
  21. sscanf(argv[4], "%d", &size);
  22. int SURF_EXTENDED = 0;
  23. int SURF_HESSIAN_THRESHOLD = 500;
  24. int SURF_NOCTAVES = 2;
  25. int SURF_NOCTAVELAYERS = 2;
  26. int MATCH_THRESHOLD = 20;
  27. CvSURFParams params = cvSURFParams(SURF_HESSIAN_THRESHOLD, SURF_EXTENDED);
  28. params.nOctaves=SURF_NOCTAVES;
  29. params.nOctaveLayers=SURF_NOCTAVELAYERS;
  30. CvMemStorage* storage = cvCreateMemStorage(0);
  31. IplImage* image = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE );
  32. CvSeq *objectKeypoints = 0, *objectDescriptors = 0;
  33. // set up the keypoint
  34. int useProvidedKeyPoints = 1;
  35. CvMemStorage* kp_storage = cvCreateMemStorage(0);
  36. CvSeq* surf_kp = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvSURFPoint), kp_storage);
  37. int laplacian = 1;
  38. int direction = 0;
  39. int hessian = SURF_HESSIAN_THRESHOLD+1;
  40. CvSURFPoint point = cvSURFPoint(cvPoint2D32f(x, y), laplacian, size, direction, hessian);
  41. cvSeqPush(surf_kp, &point);
  42. // extract descriptor
  43. cvExtractSURF(image, 0, &surf_kp, &objectDescriptors, storage, params, useProvidedKeyPoints);
  44. // print to stdout
  45. /*
  46. // if keypoint info also wanted
  47. CvSeqReader kp_reader;
  48. cvStartReadSeq(surf_kp, &kp_reader);
  49. const CvSURFPoint* kp = (const CvSURFPoint*)kp_reader.ptr;
  50. printf("%.2f %.2f %.2f %d %d",kp->pt.x,kp->pt.y,kp->hessian,kp->laplacian,kp->size);
  51. */
  52. const float* des = (const float*)cvGetSeqElem(objectDescriptors, 0);
  53. for (int i=0;i<64;i++){
  54. printf("%.5f ",des[i]);
  55. }
  56. cvReleaseImage( &image );
  57. }