/mrogh/main.cpp

https://github.com/ducha-aiki/mods · C++ · 118 lines · 84 code · 15 blank · 19 comment · 10 complexity · 40707f71202d6b3666d044a9fe7ab7ae MD5 · raw file

  1. /*
  2. An implementation of MROGH descriptor
  3. For more information, refer to:
  4. Bin Fan, Fuchao Wu and Zhanyi Hu, Aggregating Gradient Distributions into Intensity Orders: A Novel Local Image Descriptor,
  5. <EM>CVPR 2011</EM>,pp.2377-2384.
  6. Copyright (C) 2011 Bin Fan <bfan@nlpr.ia.ac.cn>
  7. All rights reserved.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. at your option any later version.
  12. See the GNU General Public License for more details.
  13. */
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include "mrogh.h"
  18. #include <ctime>
  19. int main(int argc, char** argv)
  20. {
  21. char *im_file = 0;
  22. char *feat_file = 0;
  23. char *out_file= 0;
  24. int nDir = 8, nOrder = 6, nMultiRegion = 4;
  25. int m_Dim = nDir * nOrder * nMultiRegion;
  26. int counter = 1;
  27. while( counter < argc )
  28. {
  29. if( !strcmp("-i", argv[counter] ))
  30. {
  31. im_file = argv[++counter];
  32. counter++;
  33. continue;
  34. }
  35. if( !strcmp("-f", argv[counter] ))
  36. {
  37. feat_file = argv[++counter];
  38. counter++;
  39. continue;
  40. }
  41. if( !strcmp("-o", argv[counter] ))
  42. {
  43. out_file = argv[++counter];
  44. counter++;
  45. continue;
  46. }
  47. if( !strcmp("-Dir", argv[counter] ) )
  48. {
  49. nDir = atoi(argv[++counter]);
  50. counter++;
  51. continue;
  52. }
  53. if( !strcmp("-Order", argv[counter] ) )
  54. {
  55. nOrder = atoi(argv[++counter]);
  56. counter++;
  57. continue;
  58. }
  59. if( !strcmp("-R", argv[counter] ) )
  60. {
  61. nMultiRegion = atoi(argv[++counter]);
  62. counter++;
  63. continue;
  64. }
  65. exit(1);
  66. }
  67. /* do the job */
  68. m_Dim = nDir * nOrder * nMultiRegion;
  69. clock_t start,final;
  70. start = clock();
  71. int m_nKeys = 0;
  72. OxKey *m_pKeys = ReadKeyFile(feat_file,m_nKeys);
  73. CalcuTrans(m_pKeys,m_nKeys);
  74. IplImage* m_pImg = cvLoadImage(im_file,CV_LOAD_IMAGE_GRAYSCALE);
  75. cvSmooth(m_pImg,m_pImg,CV_GAUSSIAN,5,5,1);
  76. FILE *fid = fopen(out_file,"wt");
  77. fprintf(fid,"%d\n%d\n",m_Dim,m_nKeys);
  78. int i;
  79. for (i = 0;i < m_nKeys;i++)
  80. {
  81. int *desc = 0;
  82. desc = Extract_MROGH(m_pKeys[i],m_pImg,nDir,nOrder,nMultiRegion);
  83. if ( !desc ) continue;
  84. fprintf(fid,"%f %f %f %f %f",m_pKeys[i].x,m_pKeys[i].y,m_pKeys[i].a,m_pKeys[i].b,m_pKeys[i].c);
  85. for (int j = 0;j < m_Dim;j++)
  86. {
  87. fprintf(fid," %d",desc[j]);
  88. }
  89. fprintf(fid,"\n");
  90. delete [] desc;
  91. }
  92. fclose(fid);
  93. final = clock();
  94. printf("\nUsed %lf seconds\n", (double)(final - start) / CLOCKS_PER_SEC);
  95. cvReleaseImage(&m_pImg);
  96. delete [] m_pKeys;
  97. return 0;
  98. }