Ask Your Question
0

char* to FileNode / Hide our XML configurations

asked 2018-10-15 04:36:53 -0600

laurencedev gravatar image

updated 2018-10-15 05:15:42 -0600

berak gravatar image

We use CascadeClassifier in a demo program, but we don't won't pass the xml file of the classifier directly to others. One way we were trying is to pre-compile the xml's content into the program and use it to instanlized a CascadeClassifier when it runs.

So we found that, through code like the below, the content in a xml can be compiled into the .exe(executable) file, and presented as a const char *. However, the constractors of CascadeClassifier takes either a filename or a FileNode object as a parameter for instanlization, cannot be a char*.

Is there a way to transform a const char * to a FileNode object?

const char *VX =
#include "./models/haarcascade_smile_R.xml"
;

Besides, are there anyother ways to 'hide' the configuration? Make it not so easy to be 'human-readable' as an xml.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-10-15 04:58:01 -0600

berak gravatar image

updated 2018-10-15 05:32:34 -0600

assuming, you're using opencv3, this is possible.

you can open a filestorage with data from memory:

const char *your_xml_data = ????
FileStorage fs( your_xml_data, FileStorage::MEMORY);

and read it into your CascadeClassifier:

 CascadeClassifier cascade;
 cascade.read(fs.getFirstToplevelNode());

remaining problem: how to get the xml file into a const char * ?

you can't use the original xml as a string (it contains other strings), but have to write a small prog, that reads the xml file, and generates ascii numbers from the letters, like:

const char *xmldata = {
    11,23,44,154,324,12,88,
    177,200,1,99, .....
};

once you have that, you can either paste it directly into your code, or #include it from a header.

edit flag offensive delete link more

Comments

Hi @berak, made the FileStorage part via the way you suggested.

For the 'xml to char*' one, do you suggest sth. like create a (static) function to read a xml and transform its strings into ASIIC numerical values, hard-code these values to (const char *xmldata), then, transform them back in a runtime function for the FileStorage instantization ?

laurencedev gravatar imagelaurencedev ( 2018-10-15 09:46:34 -0600 )edit

there are some examples on this site, try to find them.

no i meant a seperate program (e.g. a python script) that generates code for a c-array. but i won't write that again for you, sorry.

berak gravatar imageberak ( 2018-10-15 11:12:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-15 04:36:53 -0600

Seen: 124 times

Last updated: Oct 15 '18