Is it possible to embed a Neural Network database in c++ code for reading directly to memory?

asked 2015-03-24 19:22:45 -0600

DerekE gravatar image

updated 2015-03-25 02:43:15 -0600

berak gravatar image

I am developing an image recognition module in C++ for later deployment to Android. I have a satisfactory XML file which I currently read in using:

CvANN_MLP nnetworkRank;   
CvFileStorage* storageRank = cvOpenFileStorage("C:\\Development\\NN\\param_4.xml", 0, CV_STORAGE_READ);     
CvFileNode *nRank = cvGetFileNodeByName(storageRank, 0, "RankOCR");     
nnetworkRank.read(storageRank, nRank);    
cvReleaseFileStorage(&storageRank);

I am about to try to deploy to Android, and I want to avoid deploying the param_4 xml file with the app, and instead load it in C++ as, say, a header file to be included at compile time. I have tried including

"char param_4[258982] = {   0x3c, 0x3f, 0x78, 0x6d, ......etc" (i.e. creating a char variable consisting of the contents of my XML file) and then the following code:

**FileStorage fs(".xml", FileStorage::WRITE + FileStorage::MEMORY);  
fs << "RankOCR" << param_4; //this line crashes.  
string buf = fs.releaseAndGetString();    
FileStorage fu(buf, FileStorage::READ + FileStorage::MEMORY);

but, although it compiles, it crashes when trying to read the char variable with

 "Unhandled exception at 0x000007FEE554FFCD (opencv_core2410d.dll) in OpencvDev_1.exe: 0xC0000005: Access violation writing location 0x0000000064307827"

[environment: Visual Studio Express 2013 on Windows 7]

Any thoughts on how to include an XML file for CvANN_MLP?

edit retag flag offensive close merge delete

Comments

1

it is possible, but imho, you'll have to write to file first, then somehow read it back in and embed it into a string, finally : FileStorage fs( string_with_xml, FileStorage::READ + FileStorage::MEMORY) then get the 1st node, and let the ann read() from that.

berak gravatar imageberak ( 2015-03-25 02:57:20 -0600 )edit

Berak, Thank you for your response. What you suggest is exactly what I have been trying to do, but I suspect I'm doing something wrong because I simply can't get it to work. I have created the xml file as a char character (char param_4[25892] = { 0x3c, 0x3f ...etc...}, but I can't load it into the fs either by FileStorage fs( param_4, FileStorage::READ + FileStorage::MEMORY) or by creating fs first (as in my original question: FileStorage fs(".xml", FileStorage::WRITE + FileStorage::MEMORY); and then fs << "RankOCR" << param_4; //this line crashes. But if you're sure it should work, I will keep on trying with different formats of xml file and char. By the way, my technique for creating a char variable works fine for image files. But maybe I need to do something different for an xml file.

DerekE gravatar imageDerekE ( 2015-03-26 14:05:48 -0600 )edit