Skip to content

completely new C++ persistence implementation#13011

Merged
vpisarev merged 8 commits intoopencv:masterfrom
vpisarev:new_persistence2
Nov 1, 2018
Merged

completely new C++ persistence implementation#13011
vpisarev merged 8 commits intoopencv:masterfrom
vpisarev:new_persistence2

Conversation

@vpisarev
Copy link
Copy Markdown
Contributor

@vpisarev vpisarev commented Nov 1, 2018

replaced the old persistence (CvMemStorage, CvSeq-based) with the new C++ implementation. The new persistence provides the same C++ API. The C API has gone. FileNodeIterator is now just one-directional, but the parsed file storage takes 3-4x less memory than in the previous implementation.

@vpisarev vpisarev self-assigned this Nov 1, 2018
@vpisarev vpisarev merged commit 0f62220 into opencv:master Nov 1, 2018
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to resolve interface/public API/public headers issues.

Implementation-specific issues have lower priority and they are mostly come from previous implementation.

APPEND = 2, //!< value, open the file for appending
MEMORY = 4, //!< flag, read data from source or write data to the internal buffer (which is
//!< returned by FileStorage::release)
//!< returned by FileStorage::release)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change

The full constructor opens the file. Alternatively you can use the default constructor and then
call FileStorage::open.
The full constructor opens the file. Alternatively you can use the default constructor and then
call FileStorage::open.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary indentation changes here and below

int state; //!< the writer state
};
int state;
std::string elname;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private implementation details should be avoided.

Also related enum (line 321) should go away from public headers:

    enum
    {
        UNDEFINED      = 0,
        VALUE_EXPECTED = 1,
        NAME_EXPECTED  = 2,
        INSIDE_MAP     = 4
    };

Especially it is re-implemented here.


/** @brief Returns type of the node.
@returns Type of the node. See FileNode::Type
@returns Type of the node. See FileNode::Type
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileNode::Type

Reference is broken because name of enum is dropped.
Why?

#endif
}

static inline void writeReal(uchar* p, double fval)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API of these functions doesn't look safe.
Who controls and checks size of available buffer?

{
const uchar* p = ptr();
if( !p || (*p & TYPE_MASK) != STRING )
return std::string();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not CV_Error() ?

const uchar* p = ptr();
if( !p || (*p & TYPE_MASK) != STRING )
return std::string();
p += (*p & NAMED) ? 5 : 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5
1

Avoid magic numbers.

Usually it is more convenient to use operator `>>` instead of this method.
@param fmt Specification of each array element. See @ref format_spec "format specification"
@param vec Pointer to the destination array.
@param len Number of elements to read. If it is greater than number of remaining elements then all
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is used as buffer size.

Copy link
Copy Markdown
Contributor Author

@vpisarev vpisarev Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the description is wrong; it confused me too. it's always used as the buffer size. We need to fix it.

" -\n"
" name: algorithm\n"
" type: 9\n" // FLANN_INDEX_TYPE_ALGORITHM
" value: 6\n"// this line is changed!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is changed!

Do we still need this?
Where is it from? It is not a part of my drop CV_USRTYPE1 patch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I basically copied 1:1 one of java tests that, since I did not want to debug java tests. If we remove FLANN sometimes (not in OpenCV 4.0, I guess), this test can be removed as well.

return false;
FileNode oldroot = oldfs.getFirstTopLevelNode();

bool ok = haar_cvt::convert(oldroot, newfs);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, This conversion code should be placed near traincascade app.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disagree. Support of the old-style XML haar detector formats does not take much code, it's one little function. And it let me not to convert the old XML cascades in the test data to the new format, but rather read and use them as-is. Let's retain it in objdetect.

But it definitely makes sense to remove completely the old C-API Haar/LBP detector code from objdetect before 4.0. I'll prepare the corresponding PR shortly.

@vpisarev
Copy link
Copy Markdown
Contributor Author

vpisarev commented Nov 2, 2018

@alalek, thank you for the thorough review! at least some of the points really make sense to address. Let's merge your 3.4=>master patch and then do some other big coarse-scale changes (move modules between opencv and opencv_contrib, remove some old stuff) and then I make extra PR or a few that fix some of the found issues

@vpisarev vpisarev deleted the new_persistence2 branch November 3, 2018 23:35
endif()
endmacro()

ocv_add_app(traincascade)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are createsamples and traincascade not included in this build?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants