- 论坛徽章:
- 0
|
本帖最后由 _Genesis 于 2011-12-22 23:09 编辑
额。这个问题我实在没搞明白是怎么回事。
先是报错如下:
- || g++ -o main ex1.o header.o utils.o imgfeatures.o sift.o main.o -I. -I/home/web/include/opencv -L/home/web/lib -lm -lopencv_core -lopencv_ml -lopencv_highgui -B/home/web/lib
- || main.o: In function `main':
- || main.cpp:(.text+0x85): undefined reference to `sift_features(_IplImage*, feature**)'
- || main.cpp:(.text+0x9d): undefined reference to `sift_features(_IplImage*, feature**)'
- || main.cpp:(.text+0xb5): undefined reference to `stack_imgs1(_IplImage*, _IplImage*)'
- || collect2: ld returned 1 exit status
- || make: *** [main] 错误 1
复制代码 看提示,是没有sift_features(_IplImage*, feature**)这个函数
下面是代码。
====main.cpp====
- #include "header.h"
- #include "main.h"
- #include "sift.h"
- #include "utils.h"
- int main(int argc,char* argv[]){
- printf("hello OPENCV!!!\n========\n");
- IplImage* img1;
- IplImage* img2;
- IplImage* stacked;
- img1 = cvLoadImage(argv[1],1);
- img2 = cvLoadImage(argv[2],1);
- _showImg(img1,"img1");
- _showImg(img2,"img2");
- struct feature* ft1,*ft2,*ft;
- int n1, n2;
- n1 = sift_features(img1,&ft1);
- n2 = sift_features(img2,&ft2);
- stacked = stack_imgs1(img1,img2);
- _showImg(stacked,"stacked");
- }
复制代码 ==== sift.h ====
- /*#ifndef SIFT_H*/
- /*#define SIFT_H*/
- #include "cxcore.h"
- /******************************** Structures *********************************/
- /** holds feature data relevant to detection */
- struct detection_data
- {
- int r;
- int c;
- int octv;
- int intvl;
- double subintvl;
- double scl_octv;
- };
- struct feature;
- /******************************* Defs and macros *****************************/
- /** default number of sampled intervals per octave */
- #define SIFT_INTVLS 3
- /** default sigma for initial gaussian smoothing */
- #define SIFT_SIGMA 1.6
- /** default threshold on keypoint contrast |D(x)| */
- #define SIFT_CONTR_THR 0.04
- /** default threshold on keypoint ratio of principle curvatures */
- #define SIFT_CURV_THR 10
- /** double image size before pyramid construction? */
- #define SIFT_IMG_DBL 0
- /** default width of descriptor histogram array */
- #define SIFT_DESCR_WIDTH 4
- /** default number of bins per histogram in descriptor array */
- #define SIFT_DESCR_HIST_BINS 8
- /* assumed gaussian blur for input image */
- #define SIFT_INIT_SIGMA 0.5
- /* width of border in which to ignore keypoints */
- #define SIFT_IMG_BORDER 5
- /* maximum steps of keypoint interpolation before failure */
- #define SIFT_MAX_INTERP_STEPS 5
- /* default number of bins in histogram for orientation assignment */
- #define SIFT_ORI_HIST_BINS 36
- /* determines gaussian sigma for orientation assignment */
- #define SIFT_ORI_SIG_FCTR 1.5
- /* determines the radius of the region used in orientation assignment */
- #define SIFT_ORI_RADIUS 3.0 * SIFT_ORI_SIG_FCTR
- /* number of passes of orientation histogram smoothing */
- #define SIFT_ORI_SMOOTH_PASSES 2
- /* orientation magnitude relative to max that results in new feature */
- #define SIFT_ORI_PEAK_RATIO 0.8
- /* determines the size of a single descriptor orientation histogram */
- #define SIFT_DESCR_SCL_FCTR 3.0
- /* threshold on magnitude of elements of descriptor vector */
- #define SIFT_DESCR_MAG_THR 0.2
- /* factor used to convert floating-point descriptor to unsigned char */
- #define SIFT_INT_DESCR_FCTR 512.0
- /* returns a feature's detection data */
- #define feat_detection_data(f) ( (struct detection_data*)(f->feature_data) )
- /*************************** Function Prototypes *****************************/
- extern int sift_features( IplImage* img, struct feature** feat );
- extern int _sift_features( IplImage* img, struct feature** feat, int intvls,
- double sigma, double contr_thr, int curv_thr,
- int img_dbl, int descr_width, int descr_hist_bins );
- /*#endif*/
复制代码 ==== sift.c====
- #include "sift.h"
- #include "imgfeatures.h"
- #include "utils.h"
- #include <cxcore.h>
- #include <cv.h>
- /************************* Local Function Prototypes *************************/
- IplImage* create_init_img( IplImage*, int, double );
- IplImage* convert_to_gray32( IplImage* );
- IplImage*** build_gauss_pyr( IplImage*, int, int, double );
- IplImage* downsample( IplImage* );
- IplImage*** build_dog_pyr( IplImage***, int, int );
- CvSeq* scale_space_extrema( IplImage***, int, int, double, int, CvMemStorage*);
- int is_extremum( IplImage***, int, int, int, int );
- struct feature* interp_extremum( IplImage***, int, int, int, int, int, double);
- void interp_step( IplImage***, int, int, int, int, double*, double*, double* );
- CvMat* deriv_3D( IplImage***, int, int, int, int );
- CvMat* hessian_3D( IplImage***, int, int, int, int );
- double interp_contr( IplImage***, int, int, int, int, double, double, double );
- struct feature* new_feature( void );
- int is_too_edge_like( IplImage*, int, int, int );
- void calc_feature_scales( CvSeq*, double, int );
- void adjust_for_img_dbl( CvSeq* );
- void calc_feature_oris( CvSeq*, IplImage*** );
- double* ori_hist( IplImage*, int, int, int, int, double );
- int calc_grad_mag_ori( IplImage*, int, int, double*, double* );
- void smooth_ori_hist( double*, int );
- double dominant_ori( double*, int );
- void add_good_ori_features( CvSeq*, double*, int, double, struct feature* );
- struct feature* clone_feature( struct feature* );
- void compute_descriptors( CvSeq*, IplImage***, int, int );
- double*** descr_hist( IplImage*, int, int, double, double, int, int );
- void interp_hist_entry( double***, double, double, double, double, int, int);
- void hist_to_descr( double***, int, int, struct feature* );
- void normalize_descr( struct feature* );
- int feature_cmp( void*, void*, void* );
- void release_descr_hist( double****, int );
- void release_pyr( IplImage****, int, int );
- /*********************** Functions prototyped in sift.h **********************/
- int sift_features( IplImage* img, struct feature** feat )
- {
- return _sift_features( img, feat, SIFT_INTVLS, SIFT_SIGMA, SIFT_CONTR_THR,
- SIFT_CURV_THR, SIFT_IMG_DBL, SIFT_DESCR_WIDTH,
- SIFT_DESCR_HIST_BINS );
- }
- int _sift_features( IplImage* img, struct feature** feat, int intvls,
- double sigma, double contr_thr, int curv_thr,
- int img_dbl, int descr_width, int descr_hist_bins )
- {
- IplImage* init_img;
- IplImage*** gauss_pyr, *** dog_pyr;
- CvMemStorage* storage;
- CvSeq* features;
- int octvs, i, n = 0;
- /* check arguments */
- if( ! img )
- fatal_error( "NULL pointer error, %s, line %d", __FILE__, __LINE__ );
- if( ! feat )
- fatal_error( "NULL pointer error, %s, line %d", __FILE__, __LINE__ );
- /* build scale space pyramid; smallest dimension of top level is ~4 pixels */
- init_img = create_init_img( img, img_dbl, sigma );
- octvs = log( MIN( init_img->width, init_img->height ) ) / log(2) - 2;
- gauss_pyr = build_gauss_pyr( init_img, octvs, intvls, sigma );
- dog_pyr = build_dog_pyr( gauss_pyr, octvs, intvls );
- storage = cvCreateMemStorage( 0 );
- features = scale_space_extrema( dog_pyr, octvs, intvls, contr_thr,
- curv_thr, storage );
- calc_feature_scales( features, sigma, intvls );
- if( img_dbl )
- adjust_for_img_dbl( features );
- calc_feature_oris( features, gauss_pyr );
- compute_descriptors( features, gauss_pyr, descr_width, descr_hist_bins );
- /* sort features by decreasing scale and move from CvSeq to array */
- cvSeqSort( features, (CvCmpFunc)feature_cmp, NULL );
- n = features->total;
- *feat = calloc( n, sizeof(struct feature) );
- *feat = cvCvtSeqToArray( features, *feat, CV_WHOLE_SEQ );
- for( i = 0; i < n; i++ )
- {
- free( (*feat)[i].feature_data );
- (*feat)[i].feature_data = NULL;
- }
- cvReleaseMemStorage( &storage );
- cvReleaseImage( &init_img );
- release_pyr( &gauss_pyr, octvs, intvls + 3 );
- release_pyr( &dog_pyr, octvs, intvls + 2 );
- return n;
- }
- ...... 后面省略,应该没有问题吧
复制代码 ==== Makefile ====
- CC = g++
- C_ = gcc
- CFLAGS = -c -Wall
- COM_H = header.h
- Objs = ex1.o header.o utils.o imgfeatures.o sift.o main.o
- CVs = -I. -I/home/web/include/opencv -L/home/web/lib -lm -lopencv_core -lopencv_ml -lopencv_highgui
- main: $(Objs)
- $(CC) -o main $(Objs) $(CVs) -B/home/web/lib
- header.o: header.cpp header.h
- $(CC) $(CFLAGS) -o header.o header.cpp $(CVs) -B/home/web/lib
- ex1.o: ex1.cpp ex1.h $(COM_H)
- $(CC) $(CFLAGS) -o ex1.o ex1.cpp $(CVs) -B/home/web/lib
- utils.o:utils.c
- $(C_) $(CFLAGS) -o utils.o utils.c $(CVs) -B/home/web/lib
- imgfeatures.o:imgfeatures.c utils.c
- $(C_) $(CFLAGS) -o imgfeatures.o imgfeatures.c $(CVs) -B/home/web/lib
- sift.o:sift.c utils.c imgfeatures.c
- $(C_) $(CFLAGS) -o sift.o sift.c $(CVs) -B/home/web/lib
- main.o: main.cpp main.h $(COM_H)
- $(CC) $(CFLAGS) -o main.o main.cpp $(CVs) -B/home/web/lib
- clean:
- rm main $(Objs)
复制代码 然后是这个:
- web@pc-laptop:~/workTree/panorama/SIFT$ strings sift.o | grep feature
- sizeof(((features))->first[0]) == sizeof(CvSeqBlock) && ((features))->elem_size == sizeof(struct feature)
- calc_feature_scales
复制代码 |
|