opencv嫁接vlfeat densesift

#include <opencv2/opencv.hpp>
#include <iostream>

extern "C" {
  #include <vl/generic.h>
  #include <time.h>
  #include <stdlib.h>
#include "vl/dsift.h"
#include "vl/pgm.h"
#include "vl/mathop.h"
#include "vl/imopv.h"
}

using namespace cv;
using namespace std;

int main (int argc, const char * argv[]) {
srand(time(NULL));

Mat img;
img = imread("/home/yuhao/codes/vlfeat-0.9.20/data/roofs1.jpg", CV_LOAD_IMAGE_COLOR);   // Read the file

namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", img );                   // Show our image inside it.
waitKey(0);

VlDsiftFilter * vlf = vl_dsift_new_basic(320, 240, 1, 3);

// transform image in cv::Mat to float vector
std::vector<float> imgvec;

for (int i = 0; i < img.rows; ++i){
  for (int j = 0; j < img.cols; ++j){
    imgvec.push_back(img.at<unsigned char>(i,j) / 255.0f);                                                                                                                                                                                                        
  }
}
// call processing function of vl
vl_dsift_process(vlf, &imgvec[0]);

// echo number of keypoints found
std::cout << vl_dsift_get_keypoint_num(vlf) << std::endl;

  return 0;
}

 编译方法

g++ sift.cpp  `pkg-config --cflags --libs opencv` -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -I /home/yuhao/codes/vlfeat-0.9.20 -L /home/yuhao/codes/vlfeat-0.9.20/bin/glnxa64 -lvl

你可能感兴趣的:(opencv嫁接vlfeat densesift)