C++ 编译时SIFT代码(C+;+;)中未定义的引用
我试图检测关键点,提取一组图像的描述符,并将它们存储在文本文件中进行匹配(这将由另一段代码处理)。这是我目前所有的代码 下面是我试图在Ubuntu 12.04终端上使用g++sift1.cpp编译的代码。我已经安装了OpenCV 2.4.9C++ 编译时SIFT代码(C+;+;)中未定义的引用,c++,opencv,image-processing,sift,C++,Opencv,Image Processing,Sift,我试图检测关键点,提取一组图像的描述符,并将它们存储在文本文件中进行匹配(这将由另一段代码处理)。这是我目前所有的代码 下面是我试图在Ubuntu 12.04终端上使用g++sift1.cpp编译的代码。我已经安装了OpenCV 2.4.9 #include <iostream> #include <stdio.h> #include <dirent.h> #include <fstream> #include <string> #in
#include <iostream>
#include <stdio.h>
#include <dirent.h>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
if(argc != 2)
{
cout << "Usage: ./output <database path>" << endl;
return -1;
}
Mat img;
vector<KeyPoint> keypoints;
// SiftFeatureDetector detector;
// vector<KeyPoint> keypoints;
// detector.detect(img, keypoints);
Mat descriptor;
SIFT sift;
Mat frame_gray;
// vector<Rect> faces;
ofstream outfile_kp, outfile_des;
outfile_kp.open("keypoints_file.txt");
outfile_des.open("descriptors_file.txt");
DIR *pdir = NULL;
pdir = opendir(argv[1]);
struct dirent *pent = NULL;
while(pent == readdir(pdir))
{
if((strcmp(pent -> d_name, ".") == 0) || (strcmp(pent -> d_name, "..") == 0))
{
continue;
}
img = imread(pent -> d_name, CV_LOAD_IMAGE_GRAYSCALE);
cvtColor( img, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
sift.operator()(frame_gray,frame_gray,keypoints,descriptor,false);
// std::ostream_iterator<KeyPoint> output_iterator_kp(outfile_kp, "\n");
// std::copy(keypoints.begin(), keypoints.end(), output_iterator_kp);
// outfile_des << descriptor << endl;
// std::ostream_iterator<KeyPoint> output_iterator_des(output_des, "\n");
// std::copy(keypoints.begin(), keypoints.end(), output_iterator_des);
// outfile_kp << keypoints << endl;
// outfile_des << descriptor << endl;
}
outfile_kp.close();
outfile_des.close();
/*
Mat img_keypoints; drawkeypoints(img,keypoints,img_keypoints,Scalar::all(-1),DrawMatchesFlags::DEFAULT);
imshow("keypoints",img_keypoints);
*/
waitKey(0);
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
int main(int argc,字符**argv)
{
如果(argc!=2)
{
法院名称(“…”)==0)
{
继续;
}
img=imread(pent->d_name,CV_LOAD_IMAGE_GRAYSCALE);
CVT颜色(img、边框灰、CV灰);
均衡器历史(帧灰,帧灰);
运算符();
//std::ostream_迭代器输出_迭代器_kp(outfile_kp,“\n”);
//std::copy(keypoints.begin()、keypoints.end()、output_iterator_kp);
//outfile_des编译代码时遇到的是链接器错误。这是因为编译代码时,编译器找不到OpenCV库。因此,编译代码时需要链接OpenCV库
简单地说,这样做:
$ g++ -Wall -g -o sift sift.cpp `pkg-config --cflags --libs opencv`
上面的g++
选项启用所有警告,启用调试模式,并将使输出可执行文件名为sift
要在之后运行代码,请执行以下操作:
$ ./sift
请参阅上面的重复链接。您遇到的是链接器错误,因为在编译时,编译器找不到OpenCV库。请按照重复文章中的说明解决您的问题。非常感谢您,先生!对于重复的问题,非常抱歉;我不熟悉堆栈溢出和OpenCV…非常感谢!呵呵:)不用担心。在开始使用OpenCV时,您遇到的问题是最常见的问题之一。我以前也问过同样的问题。祝您好运!我会写一个答案,使其独立。如果答案有用,我不介意您接受我的答案:)祝您好运!是的,我做了……我是一名初级程序员……我能理解cod但连接部分等被证明是棘手的…非常感谢您的帮助,先生!
$ ./sift