-
I am trying to portal my image categorization matlab code into the C++ .NET framework so that Jessie can direcly classify test images in her .NET enviornment. I can rewrite all the code using OpenCV, but that needs quite a lot of time since the system is large, and there are some features (like Daubechies-4 wavelete transform) that OpenCV does not support at all. To reduce the burden in rewriting the code from matlab to C++, my strategy is to call matlab engine from OpenCV so that I can reuse most of the code written in matlab. It should work, but I need to try.
1 Training phase (offline).
Input: a training set file containing the features
Output: model file
Task: rewrite the training matrix into the format that can be used directly by SVM C++ ; and then call the svmtrain in the command line to get the model file.
2 testing phase (in OpenCV, and interact with matlab through matlab c engine)
2.1 Feature extraction for the images jessie passed on to me
a. In OpenCV, convert IplImage into matlab image matrix
b. In OpenCV, call the matlab engine
c. Generate the test cell matrix, test{1,...,n}, test{i}=9X6
2.2 Multi-class feature mapping
a. Input the raw test feature matrix in the format of matlab matrix
b. call the matlab engine
c. produce the multi-class feature matrix.
3. Generate the test file (in txt format) using OpenCV
Input: the multi-class test feature matrix
Output: a txt file containing the predicted label for each test image.
a. convert multi-class feature matrix into txt format
b. call the svmpredict dll to output a testresult.txt containing the predicted labels for each image.
4. Genarate svmtrain and svmpredict dll using .NET
-
for each train/test split s
for each possible parameter setting
for each fold
obtain numCat models(w,b) using 1-norm SVM trained on one fold of the training
apply the testing fold to the 5 models;
calculate an accuracty;
store the accuracy
end
end
end
-
Calling C from matlab----some experience
2007-01-31
I am using the GNU glpk toolkit to solve a linear programming problem, but unfortunately the GLPK toolkit is written for C/C++, so I have to write a mex interface so that I can directly call the GLPK from matlab.
Some online resources for writing mex and compiling mex file :
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/
1 A trick to compile multiple mex file including some .lib:
matlab prompt> mex glpkmex.cpp glpk.lib
The mex file after compiking has the extension .mexw32 on matlab version that is higher than 7.3.
2 A trick to debuge mex file through MS studio .NET and matlab
see
http://www.mathworks.com/access/helpdesk/help/techdoc/
then click "External interfaces"-->"Creating C Language MEX-Files"-->"Debugging C Language MEX-Files"
3. We can also try to compile a mex file using MS. NET, see
http://www.mee.tcd.ie/~sigmedia/intranet/coding/HowtoMex.php
4 We can also use gcc to create a mex file, see







