You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "vlfeat.h"
  2. // filter parameters
  3. static const int FKERNELSIZE = 7; //7// for gaussian blur
  4. static const float FSTDDEV = 1.5;
  5. static const int FBLOCKSIZE = 47;// 51; //47// for adaptive threshold
  6. static const int FC = -5; //-5
  7. /*
  8. ideatab a2109a
  9. android 4.1.1
  10. kernel 3.1.10
  11. bld num: a2109a_a411_03_13_121126_il
  12. hw info: 0.hy16
  13. */
  14. // A33_U70_U708HC_1511235_20160820
  15. // https://cloud.mail.ru/public/e4a01c0091ae/Allwinner%20A33
  16. vlfeatDetector::vlfeatDetector() : basicVideoAnalyzer() {
  17. m_iWidth = 0;
  18. m_iHeight = 0;
  19. m_bPIP = false;
  20. type = VA_FEAT_DETECT;
  21. //m_pCortexImage = NULL;
  22. m_oFilter = new filterImage(FKERNELSIZE, FSTDDEV, FBLOCKSIZE, FC);
  23. m_pVlDsiftFilter = NULL;
  24. m_nOldKeyPoints = 0;
  25. m_nNewKeyPoints = 0;
  26. m_pOldKeyPoints = NULL;
  27. m_pNewKeyPoints = NULL;
  28. //if( vl_get_state()->malloc_func == NULL){
  29. vl_set_simd_enabled(true);
  30. vl_set_alloc_func(malloc, realloc, calloc, free);
  31. //};
  32. int tCount = gpu::getCudaEnabledDeviceCount();
  33. if (tCount){
  34. gpu::setDevice(0);
  35. };
  36. };
  37. vlfeatDetector::~vlfeatDetector(){
  38. delete(m_oFilter);
  39. if (m_nOldKeyPoints)free(m_pOldKeyPoints);
  40. if (m_nNewKeyPoints)free(m_pNewKeyPoints);
  41. if (m_pVlDsiftFilter!=NULL)vl_dsift_delete(m_pVlDsiftFilter);
  42. //if (m_pCortexImage != NULL)delete(m_pCortexImage);
  43. };
  44. /*
  45. unsigned int root(unsigned int x){
  46. unsigned int a,b;
  47. b = x;
  48. a = x = 0x3f;
  49. x = b/x;
  50. a = x = (x+a)>>1;
  51. x = b/x;
  52. a = x = (x+a)>>1;
  53. x = b/x;
  54. x = (x+a)>>1;
  55. return(x);
  56. };
  57. */
  58. bool vlfeatDetector::m_fImageAnalyzer(Mat &Picture){
  59. if( Picture.empty() ) return false;
  60. if (m_pVlDsiftFilter == NULL){
  61. m_iWidth = Picture.cols;
  62. m_iHeight = Picture.rows;
  63. m_pVlDsiftFilter = vl_dsift_new_basic(m_iWidth, m_iHeight, DSIFT_STEP_X, DSIFT_BIN_SIZE);
  64. };
  65. if (m_pVlDsiftFilter == NULL) return false;
  66. m_oFilter->filter(Picture);
  67. //if (m_pCortexImage==NULL){
  68. // m_pCortexImage = new cortexImage(&m_oFilter->filterFrame());
  69. //return false;
  70. //} else m_pCortexImage->fillFromMat(&m_oFilter->filterFrame());
  71. free( m_pOldKeyPoints );
  72. m_nOldKeyPoints = 0;
  73. if (m_nNewKeyPoints > 0){
  74. //m_pOldKeyPoints = (VlDsiftKeypoint*)calloc(m_nNewKeyPoints, sizeof(VlDsiftKeypoint));
  75. //memccpy(m_pOldKeyPoints, m_pNewKeyPoints, m_nNewKeyPoints, sizeof(VlDsiftKeypoint));
  76. m_pOldKeyPoints = m_pNewKeyPoints;
  77. m_nOldKeyPoints = m_nNewKeyPoints;
  78. };
  79. //vl_dsift_process(m_pVlDsiftFilter, m_pCortexImage->data);
  80. m_nNewKeyPoints = vl_dsift_get_keypoint_num(m_pVlDsiftFilter);
  81. m_pNewKeyPoints = (VlDsiftKeypoint*)vl_dsift_get_keypoints(m_pVlDsiftFilter);
  82. //vl_dsift_get_descriptors(m_pVlDsiftFilter);
  83. return true;
  84. };
  85. void vlfeatDetector::markup(Mat &Picture){
  86. m_mBufferProtectorMutex.lock();
  87. //if (!m_oMat.empty()) {
  88. // cvtColor(m_oMat, Picture, CV_GRAY2BGR);
  89. //};
  90. //for (int i = 0; i < m_aGoodMatches.matches.size(); i++){
  91. // int a, b;
  92. // a = m_aGoodMatches.matches[i].trainIdx;
  93. // b = m_aGoodMatches.matches[i].queryIdx;
  94. // if (a < m_aOldKeyPoints.size() && b < m_aNewKeyPoints.size()){
  95. // //circle(Picture, m_aOldKeyPoints[a].pt, 5, Scalar(0, 255, 0), 1, 8);
  96. // //circle(Picture, m_aNewKeyPoints[b].pt, 5, Scalar(255, 0, 255), 1, 8);
  97. // line(Picture, m_aOldKeyPoints[a].pt, m_aNewKeyPoints[b].pt, Scalar(255, 255, 128), 2);
  98. // };
  99. //};
  100. for (int i = 0; i<m_nOldKeyPoints; i++)circle(Picture, Point(m_pOldKeyPoints[i].x, m_pOldKeyPoints[i].y), 5, Scalar(255, 0, 0), 1, 8);
  101. for (int i = 0; i<m_nNewKeyPoints; i++)circle(Picture, Point(m_pNewKeyPoints[i].x, m_pNewKeyPoints[i].y), 5, Scalar(0, 0, 255), 1, 8);
  102. if (m_bPIP){
  103. Mat resizedSrc;
  104. Mat subView;
  105. Mat convertedSrc;
  106. if (!m_oFilter->filterFrame().empty()){
  107. resize(m_oFilter->filterFrame(), resizedSrc, Size(160, 120), 0.0, 0.0, INTER_AREA);
  108. subView = Picture(Rect((Picture.cols - 510), 50 + 120, 160, 120));
  109. cvtColor(resizedSrc, convertedSrc, CV_GRAY2BGR);
  110. convertedSrc.copyTo(subView);
  111. };
  112. if (!m_oFilter->gaussianFrame().empty()){
  113. resize(m_oFilter->gaussianFrame(), resizedSrc, Size(160, 120), 0.0, 0.0, INTER_AREA);
  114. subView = Picture(Rect((Picture.cols - 340), 50 + 120, 160, 120));
  115. cvtColor(resizedSrc, convertedSrc, CV_GRAY2BGR);
  116. convertedSrc.copyTo(subView);
  117. };
  118. if (!m_oFilter->thresholdFrame().empty()){
  119. resize(m_oFilter->thresholdFrame(), resizedSrc, Size(160, 120), 0.0, 0.0, INTER_AREA);
  120. subView = Picture(Rect((Picture.cols - 170), 50 + 120, 160, 120));
  121. cvtColor(resizedSrc, convertedSrc, CV_GRAY2BGR);
  122. convertedSrc.copyTo(subView);
  123. };
  124. };
  125. m_mBufferProtectorMutex.unlock();
  126. };