Skip to content

Commit 0f62220

Browse files
authored
completely new C++ persistence implementation (opencv#13011)
* integrated the new C++ persistence; removed old persistence; most of OpenCV compiles fine! the tests have not been run yet * fixed multiple bugs in the new C++ persistence * fixed raw size of the parsed empty sequences * [temporarily] excluded obsolete applications traincascade and createsamples from build * fixed several compiler warnings and multiple test failures * undo changes in cocoa window rendering (that was fixed in another PR) * fixed more compile warnings and the remaining test failures (hopefully) * trying to fix the last little warning
1 parent ca55982 commit 0f62220

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5352
-8252
lines changed

apps/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ macro(ocv_add_app directory)
4949
endif()
5050
endmacro()
5151

52-
ocv_add_app(traincascade)
53-
ocv_add_app(createsamples)
52+
#ocv_add_app(traincascade)
53+
#ocv_add_app(createsamples)
5454
ocv_add_app(annotation)
5555
ocv_add_app(visualisation)
5656
ocv_add_app(interactive-calibration)

apps/traincascade/old_ml.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ class CvStatModel
144144
CV_WRAP virtual void save( const char* filename, const char* name=0 ) const;
145145
CV_WRAP virtual void load( const char* filename, const char* name=0 );
146146

147-
virtual void write( CvFileStorage* storage, const char* name ) const;
148-
virtual void read( CvFileStorage* storage, CvFileNode* node );
147+
virtual void write( cv::FileStorage& storage, const char* name ) const;
148+
virtual void read( const cv::FileNode& node );
149149

150150
protected:
151151
const char* default_model_name;
@@ -210,8 +210,8 @@ class CvNormalBayesClassifier : public CvStatModel
210210
bool update=false );
211211
CV_WRAP virtual float predict( const cv::Mat& samples, CV_OUT cv::Mat* results=0, CV_OUT cv::Mat* results_prob=0 ) const;
212212

213-
virtual void write( CvFileStorage* storage, const char* name ) const;
214-
virtual void read( CvFileStorage* storage, CvFileNode* node );
213+
virtual void write( cv::FileStorage& storage, const char* name ) const;
214+
virtual void read( const cv::FileNode& node );
215215

216216
protected:
217217
int var_count, var_all;
@@ -521,8 +521,8 @@ class CvSVM : public CvStatModel
521521

522522
static CvParamGrid get_default_grid( int param_id );
523523

524-
virtual void write( CvFileStorage* storage, const char* name ) const;
525-
virtual void read( CvFileStorage* storage, CvFileNode* node );
524+
virtual void write( cv::FileStorage& storage, const char* name ) const;
525+
virtual void read( const cv::FileNode& node );
526526
CV_WRAP int get_var_count() const { return var_idx ? var_idx->cols : var_all; }
527527

528528
protected:
@@ -538,8 +538,8 @@ class CvSVM : public CvStatModel
538538

539539
virtual float predict( const float* row_sample, int row_len, bool returnDFVal=false ) const;
540540

541-
virtual void write_params( CvFileStorage* fs ) const;
542-
virtual void read_params( CvFileStorage* fs, CvFileNode* node );
541+
virtual void write_params( cv::FileStorage& fs ) const;
542+
virtual void read_params( const cv::FileNode& node );
543543

544544
void optimize_linear_svm();
545545

@@ -673,8 +673,8 @@ struct CvDTreeTrainData
673673

674674
virtual CvDTreeNode* subsample_data( const CvMat* _subsample_idx );
675675

676-
virtual void write_params( CvFileStorage* fs ) const;
677-
virtual void read_params( CvFileStorage* fs, CvFileNode* node );
676+
virtual void write_params( cv::FileStorage& fs ) const;
677+
virtual void read_params( const cv::FileNode& node );
678678

679679
// release all the data
680680
virtual void clear();
@@ -1738,7 +1738,7 @@ class CvGBTrees : public CvStatModel
17381738
// Read parameters of the gtb model and data.
17391739
//
17401740
// API
1741-
// virtual void read_params( CvFileStorage* fs );
1741+
// virtual void read_params( const cv::FileStorage& fs );
17421742
//
17431743
// INPUT
17441744
// fs - file storage to read parameters from.

modules/calib3d/include/opencv2/calib3d.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,12 @@ square grouping and ordering algorithm fails.
843843
CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners,
844844
int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE );
845845

846+
/*
847+
Checks whether the image contains chessboard of the specific size or not.
848+
If yes, nonzero value is returned.
849+
*/
850+
CV_EXPORTS_W bool checkChessboard(InputArray img, Size size);
851+
846852
/** @brief Finds the positions of internal corners of the chessboard using a sector based approach.
847853
848854
@param image Source chessboard view. It must be an 8-bit grayscale or color image.

modules/calib3d/src/calibinit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ bool findChessboardCorners(InputArray image_, Size pattern_size,
526526
//image is binarised using a threshold dependent on the image histogram
527527
if (checkChessboardBinary(thresh_img_new, pattern_size) <= 0) //fall back to the old method
528528
{
529-
if (checkChessboard(img, pattern_size) <= 0)
529+
if (!checkChessboard(img, pattern_size))
530530
{
531531
corners_.release();
532532
return false;

modules/calib3d/src/checkchessboard.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ static bool checkQuads(vector<pair<float, int> > & quads, const cv::Size & size)
163163
int cvCheckChessboard(IplImage* src, CvSize size)
164164
{
165165
cv::Mat img = cv::cvarrToMat(src);
166-
return checkChessboard(img, size);
166+
return (int)cv::checkChessboard(img, size);
167167
}
168168

169-
int checkChessboard(const cv::Mat & img, const cv::Size & size)
169+
bool cv::checkChessboard(InputArray _img, Size size)
170170
{
171+
Mat img = _img.getMat();
171172
CV_Assert(img.channels() == 1 && img.depth() == CV_8U);
172173

173174
const int erosion_count = 1;
@@ -180,13 +181,13 @@ int checkChessboard(const cv::Mat & img, const cv::Size & size)
180181
erode(img, white, Mat(), Point(-1, -1), erosion_count);
181182
dilate(img, black, Mat(), Point(-1, -1), erosion_count);
182183

183-
int result = 0;
184+
bool result = false;
184185
for(float thresh_level = black_level; thresh_level < white_level && !result; thresh_level += 20.0f)
185186
{
186187
vector<pair<float, int> > quads;
187188
fillQuads(white, black, thresh_level + black_white_gap, thresh_level, quads);
188189
if (checkQuads(quads, size))
189-
result = 1;
190+
result = true;
190191
}
191192
return result;
192193
}

modules/calib3d/src/precomp.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ static inline bool haveCollinearPoints( const Mat& m, int count )
153153

154154
} // namespace cv
155155

156-
int checkChessboard(const cv::Mat & img, const cv::Size & size);
157156
int checkChessboardBinary(const cv::Mat & img, const cv::Size & size);
158157

159158
#endif

modules/calib3d/test/test_cameracalibration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CV_ProjectPointsTest : public cvtest::ArrayTest
5151
CV_ProjectPointsTest();
5252

5353
protected:
54-
int read_params( CvFileStorage* fs );
54+
int read_params( const cv::FileStorage& fs );
5555
void fill_array( int test_case_idx, int i, int j, Mat& arr );
5656
int prepare_test_case( int test_case_idx );
5757
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
@@ -83,7 +83,7 @@ CV_ProjectPointsTest::CV_ProjectPointsTest()
8383
}
8484

8585

86-
int CV_ProjectPointsTest::read_params( CvFileStorage* fs )
86+
int CV_ProjectPointsTest::read_params( const cv::FileStorage& fs )
8787
{
8888
int code = cvtest::ArrayTest::read_params( fs );
8989
return code;

modules/calib3d/test/test_chesscorners_timing.cpp

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
//M*/
4141

4242
#include "test_precomp.hpp"
43-
#include "opencv2/imgproc/imgproc_c.h"
44-
#include "opencv2/calib3d/calib3d_c.h"
43+
#include "opencv2/imgproc.hpp"
44+
#include "opencv2/calib3d.hpp"
4545

4646
namespace opencv_test { namespace {
4747

@@ -67,117 +67,90 @@ void CV_ChessboardDetectorTimingTest::run( int start_from )
6767
std::string filepath;
6868
std::string filename;
6969

70-
CvMat* _v = 0;
71-
CvPoint2D32f* v;
72-
73-
IplImage img;
74-
IplImage* gray = 0;
75-
IplImage* thresh = 0;
70+
std::vector<Point2f> v;
71+
Mat img, gray, thresh;
7672

7773
int idx, max_idx;
7874
int progress = 0;
7975

8076
filepath = cv::format("%scv/cameracalibration/", ts->get_data_path().c_str() );
8177
filename = cv::format("%schessboard_timing_list.dat", filepath.c_str() );
82-
CvFileStorage* fs = cvOpenFileStorage( filename.c_str(), 0, CV_STORAGE_READ );
83-
CvFileNode* board_list = fs ? cvGetFileNodeByName( fs, 0, "boards" ) : 0;
78+
cv::FileStorage fs( filename, FileStorage::READ );
79+
cv::FileNode board_list = fs["boards"];
80+
cv::FileNodeIterator bl_it = board_list.begin();
8481

85-
if( !fs || !board_list || !CV_NODE_IS_SEQ(board_list->tag) ||
86-
board_list->data.seq->total % 4 != 0 )
82+
if( !fs.isOpened() || !board_list.isSeq() || board_list.size() % 4 != 0 )
8783
{
8884
ts->printf( cvtest::TS::LOG, "chessboard_timing_list.dat can not be read or is not valid" );
8985
code = cvtest::TS::FAIL_MISSING_TEST_DATA;
9086
goto _exit_;
9187
}
9288

93-
max_idx = board_list->data.seq->total/4;
89+
max_idx = (int)(board_list.size()/4);
90+
for( idx = 0; idx < start_from; idx++ )
91+
{
92+
bl_it += 4;
93+
}
9494

9595
for( idx = start_from; idx < max_idx; idx++ )
9696
{
97-
int count0 = -1;
98-
int count = 0;
9997
Size pattern_size;
100-
int result, result1 = 0;
10198

102-
const char* imgname = cvReadString((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4), "dummy.txt");
103-
int is_chessboard = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4+1), 0);
104-
pattern_size.width = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 2), -1);
105-
pattern_size.height = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 3), -1);
99+
std::string imgname; read(*bl_it++, imgname, "dummy.txt");
100+
int is_chessboard = 0;
101+
read(*bl_it++, is_chessboard, 0);
102+
read(*bl_it++, pattern_size.width, -1);
103+
read(*bl_it++, pattern_size.height, -1);
106104

107105
ts->update_context( this, idx-1, true );
108106

109107
/* read the image */
110-
filename = cv::format("%s%s", filepath.c_str(), imgname );
108+
filename = cv::format("%s%s", filepath.c_str(), imgname.c_str() );
111109

112-
cv::Mat img2 = cv::imread( filename );
113-
img = cvIplImage(img2);
114-
115-
if( img2.empty() )
110+
img = cv::imread( filename );
111+
if( img.empty() )
116112
{
117113
ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename.c_str() );
118114
code = cvtest::TS::FAIL_MISSING_TEST_DATA;
119115
continue;
120116
}
121117

122-
ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);
123-
124-
gray = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );
125-
thresh = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );
126-
cvCvtColor( &img, gray, CV_BGR2GRAY );
127-
118+
ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname.c_str(), is_chessboard);
128119

129-
count0 = pattern_size.width*pattern_size.height;
120+
cvtColor(img, gray, COLOR_BGR2GRAY);
130121

131-
/* allocate additional buffers */
132-
_v = cvCreateMat(1, count0, CV_32FC2);
133-
count = count0;
122+
int64 _time0 = cv::getTickCount();
123+
bool result = cv::checkChessboard(gray, pattern_size);
124+
int64 _time01 = cv::getTickCount();
125+
bool result1 = findChessboardCorners(gray, pattern_size, v, 15);
126+
int64 _time1 = cv::getTickCount();
134127

135-
v = (CvPoint2D32f*)_v->data.fl;
136-
137-
int64 _time0 = cvGetTickCount();
138-
result = cvCheckChessboard(gray, cvSize(pattern_size));
139-
int64 _time01 = cvGetTickCount();
140-
141-
OPENCV_CALL( result1 = cvFindChessboardCorners(
142-
gray, cvSize(pattern_size), v, &count, 15 ));
143-
int64 _time1 = cvGetTickCount();
144-
145-
if( result != is_chessboard )
128+
if( result != (is_chessboard != 0))
146129
{
147130
ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",
148-
result ? "" : "not ", imgname );
131+
result ? "" : "not ", imgname.c_str() );
149132
code = cvtest::TS::FAIL_INVALID_OUTPUT;
150133
goto _exit_;
151134
}
152135
if(result != result1)
153136
{
154137
ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
155-
result, result1);
138+
(int)result, (int)result1);
156139
}
157140

158-
int num_pixels = gray->width*gray->height;
159-
float check_chessboard_time = float(_time01 - _time0)/(float)cvGetTickFrequency(); // in us
141+
int num_pixels = gray.cols*gray.rows;
142+
float check_chessboard_time = float(_time01 - _time0)/(float)cv::getTickFrequency(); // in us
160143
ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
161144
check_chessboard_time*1e-6, check_chessboard_time/num_pixels);
162145

163-
float find_chessboard_time = float(_time1 - _time01)/(float)cvGetTickFrequency();
146+
float find_chessboard_time = float(_time1 - _time01)/(float)cv::getTickFrequency();
164147
ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
165148
find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
166-
167-
cvReleaseMat( &_v );
168-
cvReleaseImage( &gray );
169-
cvReleaseImage( &thresh );
170149
progress = update_progress( progress, idx-1, max_idx, 0 );
171150
}
172151

173152
_exit_:
174153

175-
/* release occupied memory */
176-
cvReleaseMat( &_v );
177-
cvReleaseFileStorage( &fs );
178-
cvReleaseImage( &gray );
179-
cvReleaseImage( &thresh );
180-
181154
if( code < 0 )
182155
ts->set_failed_test_info( code );
183156
}

0 commit comments

Comments
 (0)