- int run_demo()
- {
- //cv::initModule_nonfree();
- //cout <<"initModule_nonfree() called" << endl;
- // Input and output image path.
- const char * imgInFile = "/storage/emulated/legacy/Download/sift/img1.jpg";
- const char * imgOutFile = "/storage/emulated/legacy/Download/sift/img1_result.jpg";
- Mat image;
- image = imread(imgInFile, CV_LOAD_IMAGE_COLOR);
- if(! image.data )
- {
- LOGI("11111Could not open or find the image!\n");
- return -1;
- }
- vector<KeyPoint> keypoints;
- Mat descriptors;
- // Create a SIFT keypoint detector.
- SiftFeatureDetector detector;
- detector.detect(image, keypoints);
- LOGI("Detected %d keypoints\n", (int) keypoints.size());
- // Compute feature description.
- detector.compute(image,keypoints, descriptors);
- LOGI("Compute feature.\n");
- // Store description to "descriptors.des".
- FileStorage fs;
- fs.open("descriptors.des", FileStorage::WRITE);
- LOGI("Opened file to store the features.\n");
- fs << "descriptors" << descriptors;
- LOGI("Finished writing file.\n");
- fs.release();
- LOGI("Released file.\n");
- // Show keypoints in the output image.
- Mat outputImg;
- Scalar keypointColor = Scalar(255, 0, 0);
- drawKeypoints(image, keypoints, outputImg, keypointColor, DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
- LOGI("Drew keypoints in output image file.\n");
- #ifdef WIN32
- namedWindow("Output image", CV_WINDOW_AUTOSIZE );
- imshow("Output image", outputImg);
- waitKey(0);
- #endif
- LOGI("Generate the output image.\n");
- imwrite(imgOutFile, outputImg);
- LOGI("Done.\n");
- return 0;
- }