Implementación de Sift con OpenCV 2.2


¿Alguien conoce el enlace de ejemplo de implementación de SIFT con OpenCV 2.2? saludos,

 33
Author: skaffman, 2011-03-28

5 answers

A continuación se muestra un ejemplo mínimo:

#include <opencv/cv.h>
#include <opencv/highgui.h>

int main(int argc, const char* argv[])
{
    const cv::Mat input = cv::imread("input.jpg", 0); //Load as grayscale

    cv::SiftFeatureDetector detector;
    std::vector<cv::KeyPoint> keypoints;
    detector.detect(input, keypoints);

    // Add results to image and save.
    cv::Mat output;
    cv::drawKeypoints(input, keypoints, output);
    cv::imwrite("sift_result.jpg", output);

    return 0;
}

Probado en OpenCV 2.3

 33
Author: Unapiedra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-07-15 10:44:50

Puede obtener el detector SIFT y el extractor basado en SIFT de varias maneras. Como otros ya han sugerido los métodos más directos, proporcionaré un enfoque más de "ingeniería de software" que puede hacer que el código sea más flexible a los cambios (es decir, más fácil de cambiar a otros detectores y extractores).

En primer lugar, si está buscando obtener el detector utilizando parámetros incorporados, la mejor manera es usar los métodos de fábrica de OpenCV para crearlo. He aquí cómo:

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{        
  Mat image = imread("TestImage.jpg");

  // Create smart pointer for SIFT feature detector.
  Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SIFT");
  vector<KeyPoint> keypoints;

  // Detect the keypoints
  featureDetector->detect(image, keypoints); // NOTE: featureDetector is a pointer hence the '->'.

  //Similarly, we create a smart pointer to the SIFT extractor.
  Ptr<DescriptorExtractor> featureExtractor = DescriptorExtractor::create("SIFT");

  // Compute the 128 dimension SIFT descriptor at each keypoint.
  // Each row in "descriptors" correspond to the SIFT descriptor for each keypoint
  Mat descriptors;
  featureExtractor->compute(image, keypoints, descriptors);

  // If you would like to draw the detected keypoint just to check
  Mat outputImage;
  Scalar keypointColor = Scalar(255, 0, 0);     // Blue keypoints.
  drawKeypoints(image, keypoints, outputImage, keypointColor, DrawMatchesFlags::DEFAULT);

  namedWindow("Output");
  imshow("Output", outputImage);

  char c = ' ';
  while ((c = waitKey(0)) != 'q');  // Keep window there until user presses 'q' to quit.

  return 0;

}

La razón el uso de los métodos de fábrica es flexible porque ahora puede cambiar a un detector de puntos clave o extractor de características diferentes, por ejemplo, NAVEGAR simplemente cambiando el argumento pasado a los métodos de fábrica" create " de la siguiente manera:

Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SURF");
Ptr<DescriptorExtractor> featureExtractor = DescriptorExtractor::create("SURF");

Para otros posibles argumentos a pasar para crear otros detectores o extractores ver: http://opencv.itseez.com/modules/features2d/doc/common_interfaces_of_feature_detectors.html#featuredetector-create

Http://opencv.itseez.com/modules/features2d/doc/common_interfaces_of_descriptor_extractors.html?highlight=descriptorextractor#descriptorextractor-create

Ahora, usar los métodos de fábrica significa obtener la conveniencia de no tener que adivinar algunos parámetros adecuados para pasar a cada uno de los detectores o extractores. Esto puede ser conveniente para gente nueva en usarlos. Sin embargo, si desea crear su propio detector SIFT personalizado, puede envolver el objeto SiftDetector creado con parámetros personalizados y envolverlo en un puntero inteligente y referirse a él utilizando la variable FeatureDetector smart pointer como se indica anteriormente.

 30
Author: lightalchemist,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-19 01:01:43

Un ejemplo sencillo usando SIFT nonfree feature detector en opencv 2.4

#include <opencv2/opencv.hpp>
#include <opencv2/nonfree/nonfree.hpp>
using namespace cv;

int main(int argc, char** argv)
{

    if(argc < 2)
        return -1;

    Mat img = imread(argv[1]);

    SIFT sift;
    vector<KeyPoint> key_points;

    Mat descriptors;
    sift(img, Mat(), key_points, descriptors);

    Mat output_img;
    drawKeypoints(img, key_points, output_img);

    namedWindow("Image");
    imshow("Image", output_img);
    waitKey(0);
    destroyWindow("Image");

    return 0;
}
 6
Author: AMCoded,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-02 10:47:05

OpenCV proporciona TAMIZAR y NAVEGAR (aquí también ) y otros descriptores de características listos para usar.
Tenga en cuenta que el algoritmo SIFT está patentado, por lo que puede ser incompatible con el uso/licencia regular de OpenCV.

 5
Author: Adi Shavit,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-04-12 12:41:25

Otro ejemplo sencillo usando SIFT nonfree feature detector en opencv 2.4 Asegúrese de agregar opencv_nonfree240.dependencia lib

#include "cv.h"
#include "highgui.h"
#include <opencv2/nonfree/nonfree.hpp>

int main(int argc, char** argv)
{
   cv::Mat img = cv::imread("image.jpg");

   cv::SIFT sift(10);   //number of keypoints

   cv::vector<cv::KeyPoint> key_points;

   cv::Mat descriptors, mascara;
   cv::Mat output_img;

   sift(img,mascara,key_points,descriptors);
   drawKeypoints(img, key_points, output_img);

   cv::namedWindow("Image");
   cv::imshow("Image", output_img);
   cv::waitKey(0);

   return 0;
}
 3
Author: Tervenet,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-17 01:59:17