summarylogtreecommitdiffstats
path: root/0004-opencv-hates-developers-and-suddenly-broke-cvLoadIma.patch
blob: 74fa87fe4fc616b0da075c5b119cf48304c9ccb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
From 3066e4a3a4a8aa83aaa623806aac06358e962402 Mon Sep 17 00:00:00 2001
From: "Martin T. H. Sandsmark" <martin.sandsmark@kde.org>
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 <img1> <img2>", 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;
 }
 
-- 
2.28.0