Ask Your Question

Allison's profile - activity

2017-03-11 21:43:59 -0600 asked a question SVM not being trained well in c++

I'm using SVM with hog features. When training the SVM I'm not getting the expected format which the SVM generate as below :

<?xml version="1.0"?>
<opencv_storage>
<my_svm type_id="opencv-ml-svm">
  <svm_type>C_SVC</svm_type>
  <kernel><type>LINEAR</type></kernel>
  <C>1.</C>
  <term_criteria><epsilon>1.1920928955078125e-07</epsilon>
    <iterations>1000</iterations></term_criteria>
  <var_all>1</var_all>
  <var_count>1</var_count>
  <class_count>2</class_count>
  <class_labels type_id="opencv-matrix">
    <rows>1</rows>
    <cols>2</cols>
    <dt>i</dt>
    <data>
      -1 1</data></class_labels>
  <sv_total>1</sv_total>
  <support_vectors>
    <_>
      -1.56709105e-02</_></support_vectors>
  <decision_functions>
    <_>
      <sv_count>1</sv_count>
      <rho>-1.</rho>
      <alpha>
        1.</alpha>
      <index>
        0</index></_></decision_functions></my_svm>
</opencv_storage>

instead i'm getting big whole numbers as shown :

    <?xml version="1.0"?>
<opencv_storage>
<opencv_ml_svm>
  <format>3</format>
  <svmType>C_SVC</svmType>
  <kernel>
    <type>RBF</type>
    <gamma>1.</gamma></kernel>
  <C>1.</C>
  <term_criteria><epsilon>9.9999999999999995e-07</epsilon>
    <iterations>1000</iterations></term_criteria>
  <var_count>16</var_count>
  <class_count>2</class_count>
  <class_labels type_id="opencv-matrix">
    <rows>2</rows>
    <cols>1</cols>
    <dt>i</dt>
    <data>
      -1 1</data></class_labels>
  <sv_total>2</sv_total>
  <support_vectors>
    <_>
      -431602080. -431602080. -431602080. -431602080. -431602080.
      -431602080. -431602080. -431602080. -431602080. -431602080.
      -431602080. -431602080. -431602080. -431602080. -431602080.
      -431602080.</_>
    <_>
      -431602080. -431602080. -431602080. -431602080. -431602080.
      -431602080. -431602080. -431602080. -431602080. -431602080.
      -431602080. -431602080. -431602080. -431602080. -431602080.
      -431602080.</_></support_vectors>
  <decision_functions>
    <_>
      <sv_count>2</sv_count>
      <rho>1.</rho>
      <alpha>
        1. -1.</alpha></_></decision_functions></opencv_ml_svm>
</opencv_storage>

May I know why i'm having this ?

2017-03-03 11:03:16 -0600 commented question How to use my HOG matrix in the SVM classifier?

I think you have misunderstood my question. I need to take the HOG matrix (saved as xml file) and use it in training the SVM since it contains the features. How to do it ?

2017-03-03 09:45:53 -0600 commented question How to use my HOG matrix in the SVM classifier?

Don't we have to use the xml file in the training set as shown below?

  FileStorage f("Normalised_HOG.xml", FileStorage::READ);



 // Set up training data
        vector <float> train_D, pos_D;
        int k = 0;

        for (int i = 1; i < POS + 1; i++) {
            stringstream a;
            a << i;
            f ["Descriptors" + a.str()] >> pos_D;
            for (int j = 0; j < pos_D.size(); j++) {
                train_D.push_back(pos_D[j]);
            }
        }
2017-03-03 08:08:55 -0600 commented question How to use my HOG matrix in the SVM classifier?

Yes my code is to train then save the svm classifier but the problem is i don't know how to use the normalised HOG xml file containing the features of the image in training SVM. @guidovitale

2017-03-02 18:23:25 -0600 asked a question How to use my HOG matrix in the SVM classifier?

I want to use the normalised HOG matrix which contains the features of my image. How to take the HoG matrix to use it in the SVM classifier? Does anyone has any idea how to do it?

Here is my HOG matrix:

FileStorage f("Normalised_HOG.xml", FileStorage::READ);

Here is my data labelling :

//assign label
        Mat labels(num_files, 1, CV_32FC1);

        float trainingData;
        cv::Mat trainDataMat(num_files, DESCRIPT, CV_32FC1, trainingData);

Here is my SVM Parameters

//set up SVM Parameters
    Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();
    svm->setType(SVM::C_SVC);
    svm->setKernel(SVM::LINEAR);
    svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
    // Train the SVM
    svm->train(trainDataMat, ROW_SAMPLE, labels);
    cout << "Saving Trained SVM xml ..." << endl;
    //svm->write(FileStorage("test.xml", FileStorage::WRITE));
    svm->save("SVM.xml");
2017-02-26 01:52:22 -0600 asked a question Having trouble in training SVM and predicting it in opencv 3.0 c++

I'm having problem in performing the SVM classification after extracting the HOG features of images.I'm unable to train the SVM and to do the prediction. All the features is found in the xml file and for the data labelling,the classes/objects is that, one is known to be 1(positive) and the other -1(negative). I have about 1000 frames in which 500 frames for training set and 500 frames for testing set. Please can anyone help me ?

   #include <opencv2/core.hpp>
        #include <opencv2/opencv.hpp>
        #include <opencv2/imgproc.hpp>
        #include "opencv2/imgcodecs.hpp"
        #include <opencv2/highgui.hpp>
        #include <opencv2/ml.hpp>
        #include <iostream>
        #include <fstream>
        #include<string.h>


        using namespace std;
        using namespace cv;
        using namespace cv::ml;


        int main() {
    cout<<"TRAINING DATA\n\n";
            cout<<"Feature data xml load\n";
            //Load HOG matrix
            FileStorage f("HOG.xml", FileStorage::READ);

            Mat HOGMat;

            f["Descriptor_of_images"] >> HOGMat;
            int pRow, pCol;

            pRow = HOGMat.rows;
            pCol = HOGMat.cols;
            cout<<"   pRow :"<<pRow<< "\n"<< "pCol : "<< pCol <<"\n";
            HOGMat.release();

            //Make training data for SVM

            cout << "Make training data for SVM\n";
            Mat TrainMatrix(pRow, pCol, CV_32FC1);
            memcpy(TrainMatrix.data, HOGMat.data, sizeof(float) * HOGMat.cols * HOGMat.rows);

            int startP = sizeof(float) * HOGMat.cols * HOGMat.rows;

//data labelling            
Mat labels(pRow, 1, CV_32FC1, Scalar(-1.0));
            labels.rowRange(0, pRow) = Scalar(1.0);

            //set SVM parameters
            cout << "SVM Training \n";
            Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();
            svm->setType(ml::SVM::C_SVC);
            svm->setKernel(ml::SVM::LINEAR);
            svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
            svm->train("TrainedSVM.xml");//Having ERROR - not being trained properly
            cout << "Saving trained SVM \n ";
            svm->save("TrainedSVM.xml");
    }

For the prediction:

   cout<<"TESTING DATA\n\n";


        //for predicting the label 

                //Load HOG matrix
                    FileStorage fs("HOG.xml", FileStorage::READ);
            //load trained svm xml file
            svm->load("TrainedSVM.xml");
        float result;
        svm->predict(result);
return 0;
}
2017-02-21 20:34:04 -0600 commented question An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in exe file when I run the application

Whenever i click on the button to play the video file i'm getting that exception handling. Does anyone have any idea how to solve that?

2017-02-12 11:21:33 -0600 asked a question An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in exe file when I run the application

I'm getting this error when I'm trying to run a video file in Visual C++/ CLR

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in xxxxxxxx.exe

Additional information: External component has thrown an exception.

And whenever i'm getting this error ,it is sending me to throw.cpp file. As shown below(to these c++ code) :

  //
        // Hand it off to the OS:
        //

            EHTRACE_EXIT;
    #if defined(_M_X64) && defined(_NTSUBSET_)
            RtlRaiseException( (PEXCEPTION_RECORD) &ThisException );
    #else
            RaiseException( ThisException.ExceptionCode,
                            ThisException.ExceptionFlags,
                            ThisException.NumberParameters,
                            (PULONG_PTR)&ThisException.params );
    #endif

Can anyone help me ?

2017-02-07 13:04:14 -0600 commented question Having problem with using grabcut algorithm in pictureBox of Visual C++ CLR project

An image showing hand palm ..i want to extract it from the background ..

2017-02-07 12:48:34 -0600 commented question Having problem with using grabcut algorithm in pictureBox of Visual C++ CLR project

I mean to say that the rectangle is not being drawn on the image (i.e displayed in the picturebox) when applying the grabcut function in order to separate the foreground from background ..

2017-02-07 12:24:47 -0600 asked a question Having problem with using grabcut algorithm in pictureBox of Visual C++ CLR project

I need to use the grabcut algorithm in a picturebox where the image is loaded.But i'm having trouble in using the grabcut on the image.It is not working.

Here is the grabcut function :

void grabCut( Mat image, Mat mask, Rect rect, Mat bgdModel, Mat fgdModel, int i,const int GC_INIT_WITH_RECT)
        {
            int border = 20;
            int border2 = border + border;
            Rect rectangle(border, border, image.cols - border2, image.rows - border2);
            cv::compare(mask, GC_PR_FGD, mask, CMP_EQ);
            // Generate output image
            cv::Mat foreground(image.size(), CV_8UC3, cv::Scalar(255, 255, 255));
            image.copyTo(foreground, mask); // bg pixels not copied

                                              // draw rectangle on original image
            cv::rectangle(image, rect, cv::Scalar(255, 255, 255), 1);

        }

I'm using the code found in github that is ,grabcut.cpp which is running successfully, but when applying it in the picture box ,it's not working. Any idea how i can i make it work out?Any piece of code would be of great help.. Thank you in advance..

After declaring the variable:

IplImage* frame;

//Displaying the image

pictureBox1->Image  = gcnew System::Drawing::Bitmap
(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
pictureBox1->Refresh();
2017-01-23 00:06:51 -0600 commented answer How to translate the Region of interest to the Center of gravity of the image?

@LBerger Thank you

How to use the function to align ?

2017-01-22 10:35:34 -0600 commented answer How to translate the Region of interest to the Center of gravity of the image?

Yes i want to move the contour

2017-01-22 09:45:54 -0600 commented answer How to translate the Region of interest to the Center of gravity of the image?

I have been using the following code:

//Translate the ROI to the COG of the image
    int x;
    if (COG.x > center.x)
    {
        x = COG.x - center.x;
        x = -x;
    }
    else
    {
        x = (COG.x - center.x)*-1;
    }

    int y;

    if (COG.y < center.y)
    {
        y = center.y - COG.y;
    }
    else
    {
        y = center.y - COG.y;
    }

But still no output.The object is not being positioned at the center. Did i made any mistake for the translation?

2017-01-22 07:20:44 -0600 commented question How to find the center of gravity of ROI of contour opencv 3.0 c++?

okayy i will stop closing my questions

2017-01-22 06:53:53 -0600 asked a question How to translate the Region of interest to the Center of gravity of the image?

I'm using Opencv 3.0 c++.I have been able to find the COG of an irregular object but now I need to translate the ROI to the COG of the image,that is to make it in the center.

Any suggestions how to do it?

image description

2017-01-22 02:09:22 -0600 asked a question How to find the center of gravity of ROI of contour opencv 3.0 c++?

I need to find the COG of ROI of an image so as I can translate it.I have been using moments but no results have been obtained.Neither the image is being displayed.Where is the problem?

2017-01-21 07:54:55 -0600 commented question How to extract frames in opencv 3.0 c++?

Can I use the gettickcount() function for frames?

2017-01-18 03:27:26 -0600 commented answer How to extract frames in opencv 3.0 c++?

@LBerger in fact i want to know how will i know at what fps to extract the frames from the video file.

2017-01-18 03:24:42 -0600 commented question How to extract frames in opencv 3.0 c++?

okay thanks

2017-01-18 03:01:17 -0600 commented question How to extract frames in opencv 3.0 c++?

Can you give me an idea what should i use instead of time()?

2017-01-18 00:44:10 -0600 commented answer I need help for SVM Module for training data and testing data using the HOG matrix

okay thanks.I will try to use it.

But how to save the normalised matrix after doing normalisation? i'm getting error when running the code below

Mat HogFeat = Mat(ders, true).reshape(1, 1);
        Mat mean, sigma; //save mean and standard deviation
                         //store descriptor vector into matrix
        meanStdDev(HogFeat, mean, sigma); //get mean and std deviation
        HogFeat = (HogFeat - mean) / sigma; //normalization
2017-01-18 00:42:09 -0600 asked a question How to extract frames in opencv 3.0 c++?

I want to extract frames from a video file.But how will i know at what fps to extract the frames? I have been using the code below but

long frameCounter = 0;

    std::time_t timeBegin = std::time(0);
    int tick = 0;

    cv::Mat frame;

    while (1)
    {
        cam.read(frame);

        cv::imshow("Img", frame);
        cv::waitKey(1);

        frameCounter++;

        std::time_t timeNow = std::time(0) - timeBegin;

        if (timeNow - tick >= 1)
        {
            tick++;
            cout << "Frames per second: " << frameCounter << endl;
            frameCounter = 0;
        }
    }
2017-01-17 20:29:08 -0600 commented answer I need help for SVM Module for training data and testing data using the HOG matrix

Okay. But how to use the HoG matrix and assign a label to the gesture. I have been using this. It stores in descriptor vector to make it into a matrix which can be used for training later

Hogfeat.create(ders.size(),1,CV_32FC1);

for(int i=0;i<ders.size();i++)
{
  Hogfeat.at<float>(i,0)=ders.at(i);

}
2017-01-17 12:03:48 -0600 asked a question I need help for SVM Module for training data and testing data using the HOG matrix

I'm using opencv 3.0 c++ .I need to classify gestures of hands (images).So i'm using SVM as classifier and i have been using HOG descriptor for feature extraction. Now i'm stuck in classification.

First of all i want to know how to normalize the HoG feature vector and then store the normalized HoG in a matrix So as I can use this HOG matrix in the SVM.

Now for SVM classification: For training data , how to use the HoG matrix and assign a label to the gesture? I have been able to set the SVM parameters

Can you please help me in the coding?I have no idea how to proceed even though I have looked into the opencv manual 3.0 SVM using images and the others.

2017-01-10 12:25:47 -0600 commented question How to improve the GrabCut algorithm in Opencv 3.0 c++?

@LBerger Thank you! I got it

2017-01-10 05:51:37 -0600 asked a question How to improve the GrabCut algorithm in Opencv 3.0 c++?

I have implemented the Grabcut -algorithm:

2017-01-07 00:52:11 -0600 marked best answer How to do alignment of image?

I need to do the following :

moments of the ROI

I'm unable to align the contour.