Ask Your Question

Akash Garg's profile - activity

2020-04-23 03:46:50 -0600 received badge  Popular Question (source)
2016-12-02 09:32:15 -0600 asked a question SVM trainAuto v/s train

I am using SVM for facial expression recognition using opencv. I trained my model using normal train function however my model accuracy is not too good. I want to optimize it using cross-validation testing. For it think i would need to use trainAuto. Does tainAuto first train and then perform cross-validation testing or do i need to use train and then tainAuto?? Thanks in advance!

2016-12-02 09:25:27 -0600 commented answer Confidence value for svm model

Thanks a lot!

2016-12-02 03:44:02 -0600 asked a question Confidence value for svm model

I am using SVM algorithm to recognize Facial Expression using opencv library. I want to get prediction confidence of my test image but the syntax of predict is something like float response = svm->predict(TestDataMat). How can get the confidence value?? Thanks in advance!

2016-11-18 06:05:15 -0600 asked a question SVM predicting '1' for every test image.

I am using SVM for facial expression recognition through opencv. I have trained my svm model with 50 images for each expression(happy, sad, angry) assigning labels 0,1,2 for each expression respectively, however while testing it predicts only '1' as label (that is label for sad). What should I do??

2016-11-02 07:53:32 -0600 commented answer I am trying to recognize facial emotion using SVM, however every time I run the program I get an error stating "assertion failed (samples.cols== var_count && samples.type == CV_32F) in cv::ml::SVMImpl::predict in file....... line 1919"

The next problem I am facing is the accuracy of the classifier is very poor. It ends up predicting happy emotion most of the times even when the test image emotion is not happy. What should I do??

2016-11-02 06:41:46 -0600 commented answer I am trying to recognize facial emotion using SVM, however every time I run the program I get an error stating "assertion failed (samples.cols== var_count && samples.type == CV_32F) in cv::ml::SVMImpl::predict in file....... line 1919"

Thanks @berak. Solved the problem. Actually i got confuse in reshape and resize. If my input image is 640x490, reshape(1,1) will produce an image of size(313600x1) whereas Mat TestDataMat(1, 1, CV_32FC1, &TestData) produces an image if 1x1. Therefore the size of training and testing image differs.

2016-11-01 11:20:13 -0600 commented answer I am trying to recognize facial emotion using SVM, however every time I run the program I get an error stating "assertion failed (samples.cols== var_count && samples.type == CV_32F) in cv::ml::SVMImpl::predict in file....... line 1919"

Yes @berak I did that also (the part I have commented out), but I got the same error. What should I do now????

2016-11-01 09:51:31 -0600 asked a question I am trying to recognize facial emotion using SVM, however every time I run the program I get an error stating "assertion failed (samples.cols== var_count && samples.type == CV_32F) in cv::ml::SVMImpl::predict in file....... line 1919"

For now I am trying to predict only 2 emotion- Happy & Sad. The code is given below:- int main(int argc, const char* argv) {

cout << "OpenCV Training SVM Emotion Recognition\n";
cout << "\n";

const char* path_Happy;
const char* path_Sad;
int numHappy;
int numSad;
int imageWidth=144;
int imageHeight=33;

argc=5;
argv[1]= "10";
argv[2]= "10";
argv[3]= "C:/Users/akash garg/Documents/Visual Studio 2012/Projects/ExpressionSVM/ExpressionSVM/Happy";
argv[4]= "C:/Users/akash garg/Documents/Visual Studio 2012/Projects/ExpressionSVM/ExpressionSVM/Sad";

//Check if user specify image to process
if(argc >= 5 )
{
    numHappy= atoi(argv[1]);
    numSad= atoi(argv[2]);
    path_Happy= argv[3];
    path_Sad= argv[4];

}else{
    return 0;
}        

Mat classes;
Mat trainingData;
Mat trainingImages;
vector<int> trainingLabels;

for(int i=0; i< numHappy; i++)
{

    stringstream ss(stringstream::in | stringstream::out);
    ss << path_Happy <<"/" <<i+1 << ".png";
    cout<<ss.str()<<endl;
    //Mat img=imread(ss.str(), 0);
    Mat m = imread(ss.str(), 1);
    Mat img;
    cvtColor(m,img,CV_BGR2GRAY);

    img= img.reshape(1, 1);
    trainingImages.push_back(img);
    trainingLabels.push_back(1);
}

for(int i=0; i< numSad; i++)
{
    stringstream ss(stringstream::in | stringstream::out);
    ss << path_Sad <<"/" << i+1 << ".png";
    Mat img=imread(ss.str(), 0);
    img= img.reshape(1, 1);
    trainingImages.push_back(img);
    trainingLabels.push_back(0);

}

Mat(trainingImages).copyTo(trainingData);
trainingData.convertTo(trainingData, CV_32FC1);
Mat(trainingLabels).copyTo(classes);

FileStorage fs("SVM.xml", FileStorage::WRITE);
fs << "TrainingData" << trainingData;
fs << "classes" << classes;
fs.release();
Ptr<ml::SVM> svm= ml::SVM::create();
svm->setType(ml::SVM::C_SVC);
svm->setKernel(ml::SVM::CHI2);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
svm->train(trainingData, ml::ROW_SAMPLE, classes);
svm->save("Trained.xml");
cout<<"\n SVM classifier is trained and saved.";
//svm= cv::Algorithm::load<ml::SVM>("Trained.xml"); 

//svm->load("Trained.xml");

//cv::Ptr<cv::ml::SVM> svm2= ml::SVM::create();
//svm2 = cv::ml::SVM::load<cv::ml::SVM>("Trained.xml");

svm= cv::ml::SVM::load<cv::ml::SVM>("Trained.xml");
Mat TestData= imread("C:/Users/akash garg/Documents/Visual Studio 2012/Projects/ExpressionSVM/ExpressionSVM/Test.png",0);
imshow("Test_Image", TestData);
Mat TestDataMat(1, 1, CV_32FC1, &TestData);
//TestData.convertTo(TestData, CV_32FC1);
//TestData= TestData.reshape(1,1);
//float response = svm->predict(TestData);
float response = svm->predict(TestDataMat);
if(response==1)
    cout<<"\n Happy Image Detected";
else if(response==0)
    cout<<"\n Sad Image Detected";
else
    cout<<"\n No emotion detected";
waitKey(0);
return 0;

}*

I have made the test image of same type as of training dataset but still I am getting the same error. Please help! Thanks in advance.

2016-10-12 10:31:02 -0600 commented question Create mask to select the black area

Hey Alexandra, have you found the solution to this problem?? Even I am facing this one!

2016-07-15 06:15:11 -0600 received badge  Self-Learner (source)
2016-07-15 05:50:54 -0600 answered a question CSV file creation error in face recognition

The problem was that the base path i entered in cmd was C:\Users\akash garg\Documents\Visual Studio 2012, therefore argv[1] contains only C:\Users\akash that much part. Due to this the base path is wrongly stored. To enter the path as a single unit i have to put it in inverted comas.

2016-07-12 04:35:52 -0600 asked a question CSV file creation error in face recognition

I am trying face recognition program in opencv as per the instructions given on docs.opencv.org. I have downloaded the training sample database, however I am unable to create the csv file. I am trying with the following command in the cmd * python create_csv.py c:\att > faces.csv * In faces.csv no filenames & labels are created, what i get there is just *uasage: create_csv<base_path> * Please help Thanks in advance

2016-07-12 04:24:38 -0600 commented answer Unable to understand connectedComponents() in opencv

Thank you so much!

2016-06-25 02:19:42 -0600 asked a question Error opening web camera using VideoCapture opencv

I have been trying to run a simple program of face & eye detection using opencv in Visual Studio 2012 but the web camera isn't working. There is no error on the terminal & even the web cam led gets on when I try to build the program but there a pop up window is displayed stating "The Application xyz has been blocked from accessing the Graphics hardware". I have recompiled opencv_highgui changing the "Preprocesser Definitions" in the C/C++ panel of the properties page to include: HAVE_VIDEOINPUT HAVE_DSHOW & even updated my graphic card (as mentioned on some forums) but it didn't work. Please help Thanks in advance!!

2016-06-22 10:20:29 -0600 received badge  Editor (source)
2016-06-22 10:19:09 -0600 asked a question what does svm predict() actually do?

I am learning about svm in opencv, & there I got confused about what does actually predict() do. Moreover how can I get the error following the predict() function. The code i read is given below

Mat testPredict;

svm->predict(testDataMat, testPredict);

Mat errorMat= testPredict!=testResponsesMat;

float error= 100.0f * countNonZero(errorMat) /testResponsesData.size();

where testDataMat is the Mat conversion of the vector<float> which holds the features of the image & testResponsesMat contains the Mat conversion of the vector<float> which holds the label value corresponding to the objects in the image(eg 0-nut, 1-screw, 2-bolt). Why is testPredict compared to testResponsesMat for error calculation? According to me it should be compared to testDataMat.

2016-06-21 10:36:12 -0600 received badge  Supporter (source)
2016-06-21 10:36:06 -0600 commented question Unable to understand connectedComponents() in opencv

Thanks. The link was of great help!!!

2016-06-21 10:35:20 -0600 commented answer Unable to understand connectedComponents() in opencv

So can I print the mat label? According to the explanation the background should be black and other objects having color corresponding to their label value.

2016-06-21 10:28:17 -0600 received badge  Enthusiast
2016-06-19 01:43:35 -0600 asked a question Unable to understand connectedComponents() in opencv

I am writing a program wherein i need to use connectedCompponents(img, label, connectivity= 8, type= CV_32S ). All I know is that this function returns an integer stating the no of components in the image. Then what does Mat label suggest? Thanks in advance

2016-06-18 08:00:35 -0600 commented question Trouble using threshold() function in opencv

I am basically writing an image segmentation code & my code will work only if i can make the background black objects's color other than black(then i am using watershed()). Can u suggest any way to make background black?

2016-06-18 07:55:49 -0600 commented question Trouble using threshold() function in opencv

Thank u so much. Got it now. GRAY2BGR will only convert single channel image to 3 channel. Earlier I thought it wud convert gray to color image!!!

2016-06-18 02:33:06 -0600 commented question Trouble using threshold() function in opencv

okk thanks alot. But is there any way i can threshold a 3 channel image? Converting BGR 2 Gray before using threshold() and then converting it back to BGR, will it work?

2016-06-17 03:53:30 -0600 commented question Trouble using threshold() function in opencv

bw.convertTo(bw, CV_8UC1); gives output 16 3 [259 x 194]. Why is that the channel even now remain 3?

2016-06-17 03:47:47 -0600 commented question Trouble using threshold() function in opencv

the o/p of the above command comes out to be 22 3 [259 x 194]

2016-06-17 03:07:25 -0600 asked a question Trouble using threshold() function in opencv

I am trying to segment input image using watershed method. In that i am using threshold(), however my program gets aborted with the following error on the terminal unsupported format or combination of formats () in cv::threshold The format of the function used is threshold(bw, bw, 40, 255, THRESH_BINARY); where bw is the binarised image in grayscale form.

2016-06-16 11:46:34 -0600 commented question Problem using connectedComponents() in opencv 3 using Visual Studio 2012

It worked berak. Thanks alot!!!

2016-06-16 05:57:05 -0600 asked a question Problem using connectedComponents() in opencv 3 using Visual Studio 2012

Every time I try to use connectedComponents() function of opencv in my program, the execution of the program gets Aborted with error code R6010. This is what i get on the terminal OpenCV Error: Assertion failed (L.channels() == 1 && I.channels() == 1) in connectedComponents_sub1, file /source/opencv-3.0.0/modules/imgproc/src/connectedcomponents.cpp, line 341