spacepaste

  1.  
  2. int run_demo()
  3. {
  4. //cv::initModule_nonfree();
  5. //cout <<"initModule_nonfree() called" << endl;
  6. // Input and output image path.
  7. const char * imgInFile = "/storage/emulated/legacy/Download/sift/img1.jpg";
  8. const char * imgOutFile = "/storage/emulated/legacy/Download/sift/img1_result.jpg";
  9. Mat image;
  10. image = imread(imgInFile, CV_LOAD_IMAGE_COLOR);
  11. if(! image.data )
  12. {
  13. LOGI("11111Could not open or find the image!\n");
  14. return -1;
  15. }
  16. vector<KeyPoint> keypoints;
  17. Mat descriptors;
  18. // Create a SIFT keypoint detector.
  19. SiftFeatureDetector detector;
  20. detector.detect(image, keypoints);
  21. LOGI("Detected %d keypoints\n", (int) keypoints.size());
  22. // Compute feature description.
  23. detector.compute(image,keypoints, descriptors);
  24. LOGI("Compute feature.\n");
  25. // Store description to "descriptors.des".
  26. FileStorage fs;
  27. fs.open("descriptors.des", FileStorage::WRITE);
  28. LOGI("Opened file to store the features.\n");
  29. fs << "descriptors" << descriptors;
  30. LOGI("Finished writing file.\n");
  31. fs.release();
  32. LOGI("Released file.\n");
  33. // Show keypoints in the output image.
  34. Mat outputImg;
  35. Scalar keypointColor = Scalar(255, 0, 0);
  36. drawKeypoints(image, keypoints, outputImg, keypointColor, DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
  37. LOGI("Drew keypoints in output image file.\n");
  38. #ifdef WIN32
  39. namedWindow("Output image", CV_WINDOW_AUTOSIZE );
  40. imshow("Output image", outputImg);
  41. waitKey(0);
  42. #endif
  43. LOGI("Generate the output image.\n");
  44. imwrite(imgOutFile, outputImg);
  45. LOGI("Done.\n");
  46. return 0;
  47. }
  48.