Ask Your Question

adhitomax's profile - activity

2016-09-09 10:01:56 -0500 received badge  Student (source)
2014-10-06 11:40:57 -0500 asked a question Read svm data and re-train with more data

I am implementing a facial expression recognition and am using SVM to classify given expression. When I train, I use this command line

svm.train(myFeatureVector,myLabels,Mat(),Mat(), myParameters);
svm.save("myClassifier.yml");

which will later when I will predict using

response = svm.predict(incomingFeatureVector);

But then when I want to train more than once (exited the program and start again), it seems to have overwritten my previous svm file. Is there any way I could do read previous svm file and add more data into it (and then resave it ,etc) ? I looked up on this openCV documentation and found nothing. However, when I read on this page; there is a method called CvSVM::read. I don't know what that does/how to implement it.

Hope anyone can help me :(

2014-09-30 02:22:01 -0500 asked a question OpenCV Android: wait for user input?

I am implementing a facial expression recognition (FER) in openCV, entirely on C++.

Now that my program is up and ready, I am planning to implement this in Android using JNI so that I do not have to change my code.

I have three stages in my program, which is as follows:

Face-detection using cascade classifier Local Binary Pattern to determine feature Vector Expression Classification using Support Vector Machine I have two 'modes' which are:

Training mode, where the program asks user to mimic different expressions, process them to determine feature vectors, then train the SVM 'Live' Mode, where the program determines the predicted expression on given expression. My problem lies on the training mode. In executable program, I use getchar to wait for user (so that they can change their expression and then press Enter to mimic the next expression) and then take 100 face images, etc so on until I get images for all expressions. In this way user can 'get ready' for the next expression.

Now, I do not know how to do this in android programming , since I am really not used to it.

I want to maybe, take the first 100 face images for one expression, wait for user to touch the screen, then take another 100 face images expression, and so on.

So generally what I am asking is, how to program in such a way that I can wait for user input before proceeding to the next step ?

Sorry for my bad english, not my first language so hope you guys don't mind.

Here is a snippet of my code (only the Java part) so you guys have some idea.

public class Tutorial2Activity extends Activity implements CvCameraViewListener2 {
private static final String    TAG = "OCVSample::Activity";

private static final int       VIEW_MODE_LIVE_MODE         = 0;
private static final int       VIEW_MODE_TRAINING_MODE     = 1;

private int                    mViewMode;
private Mat                    mRgba;
private Mat                    mIntermediateMat;
private Mat                    mGray;

private File                   mCascadeFileEyes;
private File                   mCascadeFileClassifier;

private MenuItem               mItemLiveMode;
private MenuItem               mItemTrainingMode;
private int                    mCameraId;
private CameraBridgeViewBase   mOpenCvCameraView;


private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");

                // Load native library after(!) OpenCV initialization
                System.loadLibrary("mixed_sample");

                mCameraId = 1;
                mOpenCvCameraView.setCameraIndex(mCameraId);

                InputStream is, isClassifier;
                FileOutputStream os, osClassifier;

                try {
                    is = getResources().getAssets().open("lbpcascade_frontalface.xml");
                    File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
                    mCascadeFileEyes = new File(cascadeDir, "lbpcascade_frontalface.xml");

                    //FileOutputStream os;
                    os = new FileOutputStream(mCascadeFileEyes);

                    byte[] buffer = new byte[16384];
                    int bytesRead;
                    while ((bytesRead = is.read(buffer)) != -1) {
                        os.write(buffer, 0, bytesRead);
                    }

                    is.close();
                    os.close();
                    Log.i(TAG, "face cascade found");
                } catch (IOException e) {
                    Log.i(TAG, "face cascade not found");
                }

                try {
                    isClassifier = getResources().getAssets().open("svmClassifier.yml");
                    File cascadeDirClassifier = getDir("cascade", Context.MODE_PRIVATE);
                    mCascadeFileClassifier = new File(cascadeDirClassifier, "svmClassifier.yml");

                    //FileOutputStream os;
                    osClassifier = new FileOutputStream(mCascadeFileClassifier);

                    byte[] bufferClassifier = new byte[16384];
                    int bytesReadClassifer;
                    while ((bytesReadClassifer = isClassifier.read(bufferClassifier)) != -1) {
                        osClassifier.write(bufferClassifier, 0, bytesReadClassifer);
                    }

                    isClassifier.close();
                    osClassifier.close();
                    Log.i(TAG, "svmClassifier found");
                } catch (IOException e) {
                    Log.i(TAG, "svmClassifier not ...
(more)