From 1d86dcb6dc7009aa6292549dea431f3018104b92 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 11 Oct 2020 13:36:54 +0200 Subject: [PATCH 1/6] the opencv4 C API is broken --- Makefile | 2 +- include/utils.h | 2 +- src/Makefile | 4 ++-- src/dspfeat.c | 2 +- src/siftfeat.c | 2 +- src/utils.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 6b7b7b7..339bde6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CC = gcc +CC = g++ CFLAGS += -O3 BIN_DIR = ./bin SRC_DIR = ./src diff --git a/include/utils.h b/include/utils.h index 770067b..af2d8eb 100644 --- a/include/utils.h +++ b/include/utils.h @@ -156,7 +156,7 @@ extern char* prepend_path( const char* path, const char* file ); @return Returns the basename of \a pathname. */ -extern char* basename( const char* pathname ); +extern char* sift_basename( const char* pathname ); /** diff --git a/src/Makefile b/src/Makefile index 407118d..4099907 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ -CC = gcc -CFLAGS += +CC = g++ +CFLAGS += -fpermissive -Wno-deprecated-declarations -Wno-write-strings BIN_DIR = ../bin INC_DIR = ../include LIB_DIR = ../lib diff --git a/src/dspfeat.c b/src/dspfeat.c index 9aeba1c..ec16aec 100644 --- a/src/dspfeat.c +++ b/src/dspfeat.c @@ -85,7 +85,7 @@ static void usage( char* name ) */ static void arg_parse( int argc, char** argv ) { - pname = basename( argv[0] ); + pname = sift_basename( argv[0] ); int arg; while( 1 ) { diff --git a/src/siftfeat.c b/src/siftfeat.c index fec82a7..0e90ed7 100644 --- a/src/siftfeat.c +++ b/src/siftfeat.c @@ -126,7 +126,7 @@ static void usage( char* name ) static void arg_parse( int argc, char** argv ) { //extract program name from command line (remove path, if present) - pname = basename( argv[0] ); + pname = sift_basename( argv[0] ); //parse commandline options while( 1 ) diff --git a/src/utils.c b/src/utils.c index b819fc6..716ac3c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -105,7 +105,7 @@ char* prepend_path( const char* path, const char* file ) @return Returns the basename of \a pathname. */ -char* basename( const char* pathname ) +char* sift_basename( const char* pathname ) { char* base, * last_slash; From bb6d446322e299da03ba26ce0201e8c4a937b8d4 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 11 Oct 2020 13:37:41 +0200 Subject: [PATCH 2/6] opencv has fucked up their headers again --- include/imgfeatures.h | 2 +- include/kdtree.h | 2 +- include/sift.h | 2 +- include/utils.h | 2 +- include/xform.h | 2 +- src/dspfeat.c | 4 ++-- src/imgfeatures.c | 2 +- src/kdtree.c | 2 -- src/match.c | 5 ++--- src/match_num.c | 5 ++--- src/sift.c | 3 --- src/siftfeat.c | 4 +++- src/utils.c | 4 +--- src/xform.c | 2 -- 14 files changed, 16 insertions(+), 25 deletions(-) diff --git a/include/imgfeatures.h b/include/imgfeatures.h index 1d8224e..f2523bd 100644 --- a/include/imgfeatures.h +++ b/include/imgfeatures.h @@ -9,7 +9,7 @@ #ifndef IMGFEATURES_H #define IMGFEATURES_H -#include "cxcore.h" +#include /** FEATURE_OXFD
FEATURE_LOWE */ enum feature_type diff --git a/include/kdtree.h b/include/kdtree.h index d244a85..980c1e8 100644 --- a/include/kdtree.h +++ b/include/kdtree.h @@ -18,7 +18,7 @@ #ifndef KDTREE_H #define KDTREE_H -#include "cxcore.h" +#include /********************************* Structures ********************************/ diff --git a/include/sift.h b/include/sift.h index 5711448..cc621c3 100644 --- a/include/sift.h +++ b/include/sift.h @@ -20,7 +20,7 @@ #ifndef SIFT_H #define SIFT_H -#include "cxcore.h" +#include /******************************** Structures *********************************/ diff --git a/include/utils.h b/include/utils.h index af2d8eb..234685c 100644 --- a/include/utils.h +++ b/include/utils.h @@ -9,7 +9,7 @@ #ifndef UTILS_H #define UTILS_H -#include "cxcore.h" +#include #include #include diff --git a/include/xform.h b/include/xform.h index baca8d5..b4d70c8 100644 --- a/include/xform.h +++ b/include/xform.h @@ -9,7 +9,7 @@ #ifndef XFORM_H #define XFORM_H -#include +#include /********************************** Structures *******************************/ diff --git a/src/dspfeat.c b/src/dspfeat.c index ec16aec..a7e05d8 100644 --- a/src/dspfeat.c +++ b/src/dspfeat.c @@ -9,8 +9,8 @@ #include "imgfeatures.h" #include "utils.h" -#include -#include +#include +#include #include diff --git a/src/imgfeatures.c b/src/imgfeatures.c index 4e518d4..6b011d6 100644 --- a/src/imgfeatures.c +++ b/src/imgfeatures.c @@ -9,7 +9,7 @@ #include "utils.h" #include "imgfeatures.h" -#include +#include static int import_oxfd_features( char*, struct feature** ); static int export_oxfd_features( char*, struct feature*, int ); diff --git a/src/kdtree.c b/src/kdtree.c index a7bdb06..c80ba76 100644 --- a/src/kdtree.c +++ b/src/kdtree.c @@ -19,8 +19,6 @@ #include "imgfeatures.h" #include "utils.h" -#include - #include struct bbf_data diff --git a/src/match.c b/src/match.c index fe6f360..badeb51 100644 --- a/src/match.c +++ b/src/match.c @@ -12,9 +12,8 @@ #include "utils.h" #include "xform.h" -#include -#include -#include +#include +#include #include diff --git a/src/match_num.c b/src/match_num.c index 7a74cac..2da31c8 100644 --- a/src/match_num.c +++ b/src/match_num.c @@ -12,9 +12,8 @@ #include "utils.h" #include "xform.h" -#include -#include -#include +#include +#include #include #include diff --git a/src/sift.c b/src/sift.c index e0cb6e3..86c9274 100644 --- a/src/sift.c +++ b/src/sift.c @@ -21,9 +21,6 @@ #include "imgfeatures.h" #include "utils.h" -#include -#include - /************************* Local Function Prototypes *************************/ static IplImage* create_init_img( IplImage*, int, double ); diff --git a/src/siftfeat.c b/src/siftfeat.c index 0e90ed7..0b841d7 100644 --- a/src/siftfeat.c +++ b/src/siftfeat.c @@ -19,7 +19,9 @@ #include "imgfeatures.h" #include "utils.h" -#include +#include +#include +#include #include diff --git a/src/utils.c b/src/utils.c index 716ac3c..1923fca 100644 --- a/src/utils.c +++ b/src/utils.c @@ -8,9 +8,7 @@ #include "utils.h" -#include -#include -#include +#include #include #include diff --git a/src/xform.c b/src/xform.c index 1560994..eb45d17 100644 --- a/src/xform.c +++ b/src/xform.c @@ -11,8 +11,6 @@ #include "imgfeatures.h" #include "utils.h" -#include - #include #include From fc9e39be111615b20ea126cf58d95a912cec0e8c Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 11 Oct 2020 13:38:21 +0200 Subject: [PATCH 3/6] opencv broke CV_RGB --- include/imgfeatures.h | 4 ++-- src/imgfeatures.c | 6 +++--- src/match.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/imgfeatures.h b/include/imgfeatures.h index f2523bd..7e10b09 100644 --- a/include/imgfeatures.h +++ b/include/imgfeatures.h @@ -28,8 +28,8 @@ enum feature_match_type /* colors in which to display different feature types */ -#define FEATURE_OXFD_COLOR CV_RGB(255,255,0) -#define FEATURE_LOWE_COLOR CV_RGB(255,0,255) +#define FEATURE_OXFD_COLOR {255,255,0} +#define FEATURE_LOWE_COLOR {255,0,255} /** max feature descriptor length */ #define FEATURE_MAX_D 128 diff --git a/src/imgfeatures.c b/src/imgfeatures.c index 6b011d6..e417563 100644 --- a/src/imgfeatures.c +++ b/src/imgfeatures.c @@ -336,7 +336,7 @@ static int export_oxfd_features( char* filename, struct feature* feat, int n ) */ static void draw_oxfd_features( IplImage* img, struct feature* feat, int n ) { - CvScalar color = CV_RGB( 255, 255, 255 ); + CvScalar color ({ 255, 255, 255 }); int i; if( img-> nChannels > 1 ) @@ -374,7 +374,7 @@ static void draw_oxfd_feature( IplImage* img, struct feature* feat, alpha *= 180 / M_PI; cvEllipse( img, cvPoint( feat->x, feat->y ), cvSize( l2, l1 ), alpha, - 0, 360, CV_RGB(0,0,0), 3, 8, 0 ); + 0, 360, {0,0,0}, 3, 8, 0 ); cvEllipse( img, cvPoint( feat->x, feat->y ), cvSize( l2, l1 ), alpha, 0, 360, color, 1, 8, 0 ); cvLine( img, cvPoint( feat->x+2, feat->y ), cvPoint( feat->x-2, feat->y ), @@ -543,7 +543,7 @@ static int export_lowe_features( char* filename, struct feature* feat, int n ) */ static void draw_lowe_features( IplImage* img, struct feature* feat, int n ) { - CvScalar color = CV_RGB( 255, 255, 255 ); + CvScalar color ({ 255, 255, 255 }); int i; if( img-> nChannels > 1 ) diff --git a/src/match.c b/src/match.c index badeb51..d11d9b4 100644 --- a/src/match.c +++ b/src/match.c @@ -64,8 +64,8 @@ int main( int argc, char** argv ) { pt1 = cvPoint( cvRound( feat->x ), cvRound( feat->y ) ); pt2 = cvPoint( cvRound( nbrs[0]->x ), cvRound( nbrs[0]->y ) ); - pt2.y += img1->height; - cvLine( stacked, pt1, pt2, CV_RGB(255,0,255), 1, 8, 0 ); + pt2.y += img1.height; + cvLine( stacked, pt1, pt2, {255,0,255}, 1, 8, 0 ); m++; feat1[i].fwd_match = nbrs[0]; } From 2250e4259e83787b4d943e338ace4652548bfcac Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 11 Oct 2020 13:39:52 +0200 Subject: [PATCH 4/6] opencv hates developers and suddenly broke cvLoadImage --- src/dspfeat.c | 10 +++++----- src/match.c | 18 ++++++++---------- src/match_num.c | 9 ++++----- src/siftfeat.c | 14 +++++++------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/dspfeat.c b/src/dspfeat.c index a7e05d8..fe94123 100644 --- a/src/dspfeat.c +++ b/src/dspfeat.c @@ -34,24 +34,24 @@ int feat_type = FEATURE_LOWE; int main( int argc, char** argv ) { - IplImage* img; + IplImage img; struct feature* feat; char* name; int n; arg_parse( argc, argv ); - img = cvLoadImage( img_file, 1 ); - if( ! img ) + img = cvIplImage(cv::imread( img_file, 1 )); + if( ! img.imageSize ) fatal_error( "unable to load image from %s", img_file ); n = import_features( feat_file, feat_type, &feat ); if( n == -1 ) fatal_error( "unable to import features from %s", feat_file ); name = feat_file; - draw_features( img, feat, n ); + draw_features( &img, feat, n ); cvNamedWindow( name, 1 ); - cvShowImage( name, img ); + cvShowImage( name, &img ); cvWaitKey( 0 ); return 0; } diff --git a/src/match.c b/src/match.c index d11d9b4..0a27a0e 100644 --- a/src/match.c +++ b/src/match.c @@ -27,7 +27,7 @@ int main( int argc, char** argv ) { - IplImage* img1, * img2, * stacked; + IplImage img1, img2, * stacked; struct feature* feat1, * feat2, * feat; struct feature** nbrs; struct kd_node* kd_root; @@ -38,18 +38,18 @@ int main( int argc, char** argv ) if( argc != 3 ) fatal_error( "usage: %s ", argv[0] ); - img1 = cvLoadImage( argv[1], 1 ); - if( ! img1 ) + img1 = cvIplImage(cv::imread( argv[1], 1 )); + if( ! img1.imageSize ) fatal_error( "unable to load image from %s", argv[1] ); - img2 = cvLoadImage( argv[2], 1 ); - if( ! img2 ) + img2 = cvIplImage(cv::imread( argv[2], 1 )); + if( ! img2.imageSize ) fatal_error( "unable to load image from %s", argv[2] ); - stacked = stack_imgs( img1, img2 ); + stacked = stack_imgs( &img1, &img2 ); fprintf( stderr, "Finding features in %s...\n", argv[1] ); - n1 = sift_features( img1, &feat1 ); + n1 = sift_features( &img1, &feat1 ); fprintf( stderr, "Finding features in %s...\n", argv[2] ); - n2 = sift_features( img2, &feat2 ); + n2 = sift_features( &img2, &feat2 ); fprintf( stderr, "Building kd tree...\n" ); kd_root = kdtree_build( feat2, n2 ); for( i = 0; i < n1; i++ ) @@ -108,8 +108,6 @@ int main( int argc, char** argv ) */ cvReleaseImage( &stacked ); - cvReleaseImage( &img1 ); - cvReleaseImage( &img2 ); kdtree_release( kd_root ); free( feat1 ); free( feat2 ); diff --git a/src/match_num.c b/src/match_num.c index 2da31c8..0e3bdd0 100644 --- a/src/match_num.c +++ b/src/match_num.c @@ -42,15 +42,14 @@ struct thread_data { void* process_image(void* arg) { int n; struct thread_data* ctx; - IplImage* img; + IplImage img; ctx = (struct thread_data*)arg; - img = cvLoadImage(ctx->filename, 1); - if (!img) fatal_error("Unable to load image from %s", ctx->filename); - ctx->fdata.count = sift_features(img, &(ctx->fdata.features)); + img = cvIplImage(cv::imread(ctx->filename, 1)); + if (!img.imageSize) fatal_error("Unable to load image from %s", ctx->filename); + ctx->fdata.count = sift_features(&img, &(ctx->fdata.features)); if (DEBUG) fprintf(stderr, "Found %d features in %s...\n", ctx->fdata.count, ctx->filename); - cvReleaseImage(&img); pthread_exit(NULL); } diff --git a/src/siftfeat.c b/src/siftfeat.c index 0b841d7..0a87bf9 100644 --- a/src/siftfeat.c +++ b/src/siftfeat.c @@ -52,24 +52,24 @@ int display = 1; int main( int argc, char** argv ) { - IplImage* img; + IplImage img; struct feature* features; int n = 0; arg_parse( argc, argv ); fprintf( stderr, "Finding SIFT features...\n" ); - img = cvLoadImage( img_file_name, 1 ); - if( ! img ) + img = cvIplImage(cv::imread( img_file_name, 1 )); + if( ! img.imageSize ) fatal_error( "unable to load image from %s", img_file_name ); - n = _sift_features( img, &features, intvls, sigma, contr_thr, curv_thr, + n = _sift_features( &img, &features, intvls, sigma, contr_thr, curv_thr, img_dbl, descr_width, descr_hist_bins ); fprintf( stderr, "Found %d features.\n", n ); if( display ) { - draw_features( img, features, n ); - display_big_img( img, img_file_name ); + draw_features( &img, features, n ); + display_big_img( &img, img_file_name ); cvWaitKey( 0 ); } @@ -77,7 +77,7 @@ int main( int argc, char** argv ) export_features( out_file_name, features, n ); if( out_img_name != NULL ) - cvSaveImage( out_img_name, img, NULL ); + cv::imwrite( out_img_name, cv::cvarrToMat(&img) ); return 0; } From ab47d8f8ea8463e3aa8ddb1c823141f0cb48846f Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 11 Oct 2020 13:40:14 +0200 Subject: [PATCH 5/6] opencv has broken their pkgconfig --- src/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index 4099907..f466043 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,8 +3,8 @@ CFLAGS += -fpermissive -Wno-deprecated-declarations -Wno-write-strings BIN_DIR = ../bin INC_DIR = ../include LIB_DIR = ../lib -INCL = -I$(INC_DIR) `pkg-config --cflags opencv gtk+-2.0` -LIBS = -L$(LIB_DIR) -lopensift -lm `pkg-config --libs opencv gtk+-2.0` +INCL = -I$(INC_DIR) `pkg-config --cflags opencv4 gtk+-2.0` +LIBS = -L$(LIB_DIR) -lopensift -lm -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core `pkg-config --libs gtk+-2.0` OBJ = imgfeatures.o utils.o sift.o kdtree.o minpq.o xform.o BIN = siftfeat match dspfeat match_num From ce2bd026732f84c55c33e0dcb3979242a483ae25 Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sun, 11 Oct 2020 13:40:30 +0200 Subject: [PATCH 6/6] build shared library --- Makefile | 6 +++--- src/Makefile | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 339bde6..608d318 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,12 @@ INC_DIR = ./include LIB_DIR = ./lib BIN = siftfeat match dspfeat match_num -all: $(BIN) libopensift.a docs +all: $(BIN) libopensift.so docs docs: doxygen Doxyfile -libopensift.a: +libopensift.so: make -C $(SRC_DIR) $@ $(BIN): @@ -29,4 +29,4 @@ distclean: clean docsclean: rm -rf $(DOC_DIR)/html/ -.PHONY: docs clean docsclean libopensift.a +.PHONY: docs clean docsclean libopensift.so diff --git a/src/Makefile b/src/Makefile index f466043..3290c01 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,30 +1,29 @@ CC = g++ -CFLAGS += -fpermissive -Wno-deprecated-declarations -Wno-write-strings +CFLAGS += -fpermissive -Wno-deprecated-declarations -Wno-write-strings -fPIC BIN_DIR = ../bin INC_DIR = ../include LIB_DIR = ../lib INCL = -I$(INC_DIR) `pkg-config --cflags opencv4 gtk+-2.0` -LIBS = -L$(LIB_DIR) -lopensift -lm -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core `pkg-config --libs gtk+-2.0` +LIBS = -L$(LIB_DIR) -lm -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core OBJ = imgfeatures.o utils.o sift.o kdtree.o minpq.o xform.o BIN = siftfeat match dspfeat match_num -all: $(BIN) libopensift.a +all: $(BIN) libopensift.so -libopensift.a: $(OBJ) - ar rc $(LIB_DIR)/$@ $(OBJ) - ranlib $(LIB_DIR)/$@ +libopensift.so: $(OBJ) + g++ -shared $(CFLAGS) $(LDFLAGS) -o $(LIB_DIR)/$@ $^ $(LIBS) -siftfeat: libopensift.a siftfeat.c - $(CC) $(CFLAGS) $(INCL) siftfeat.c -o $(BIN_DIR)/$@ $(LIBS) +siftfeat: libopensift.so siftfeat.c + $(CC) $(CFLAGS) $(INCL) siftfeat.c -o $(BIN_DIR)/$@ -lopensift $(LIBS) -match: libopensift.a match.c - $(CC) $(CFLAGS) $(INCL) match.c -o $(BIN_DIR)/$@ $(LIBS) +match: libopensift.so match.c + $(CC) $(CFLAGS) $(INCL) match.c -o $(BIN_DIR)/$@ -lopensift $(LIBS) -match_num: libopensift.a match.c - $(CC) $(CFLAGS) $(INCL) match_num.c -o $(BIN_DIR)/$@ $(LIBS) +match_num: libopensift.so match.c + $(CC) $(CFLAGS) $(INCL) match_num.c -o $(BIN_DIR)/$@ -lopensift $(LIBS) -dspfeat: libopensift.a dspfeat.c - $(CC) $(CFLAGS) $(INCL) dspfeat.c -o $(BIN_DIR)/$@ $(LIBS) +dspfeat: libopensift.so dspfeat.c + $(CC) $(CFLAGS) $(INCL) dspfeat.c -o $(BIN_DIR)/$@ -lopensift $(LIBS) imgfeatures.o: imgfeatures.c $(INC_DIR)/imgfeatures.h $(CC) $(CFLAGS) $(INCL) -c imgfeatures.c -o $@