Ask Your Question

Biswesh's profile - activity

2015-03-06 06:51:06 -0600 asked a question I am trying to estimate gamma for my training images.Can anyone tell why I always get the Gamma and C values as 1?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>
#include <iostream>
#include <dirent.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <vector>
#include<unistd.h>
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

int main(int argc, char ** argv)
{


int img_area=17280;
int len=0;
float x=1;
int y,z;
int m;
int g=1;
int j =1;

Mat img1;
Mat trainmat2;

float labels[100];

for (int l=0; l<100; l++ )
{
if((l+1) % 10 == 1 && l != 0)
{
 x = x+1;
}
labels[l]=x;

}

Mat labelsMat(100,1,CV_32FC1, labels);

struct dirent *pDirent;
DIR *pDir;
pDir = opendir("/home/bapi/workspace/pics");

if(pDir != NULL)
{
while((pDirent = readdir(pDir))!=NULL)
{
if ((strcmp(pDirent->d_name,".")!=0) && (strcmp(pDirent->d_name,"..")!=0) && (strcmp(pDirent->d_name,"Thumbs.db")!=0))
{ 
len=len+1;
}
}
}
closedir (pDir);

cv::Mat trainmat((len),img_area,CV_32FC1);

Mat trainmat1;


cv::Mat img;
cv::Mat img2;
cv::Mat img3;

cv::Mat pred;


for (int i=1;i<=len;i++)
{
int Number = i;
string Result;
stringstream convert; 

convert << Number;

Result = convert.str();

std::string name("/home/bapi/workspace/pics/");
name += Result;
name += ".jpg";


img2=imread(name,CV_LOAD_IMAGE_GRAYSCALE);
img2.convertTo(img,CV_32FC1);




if(i==1)
{
trainmat=img.reshape(0,1);


}
else
{

trainmat.push_back(img.reshape(0,1));

}
}


CvParamGrid CvParamGrid_C(pow(2.0,-5), pow(2.0,15), pow(2.0,2));
CvParamGrid CvParamGrid_gamma(pow(2.0,-15), pow(2.0,3), pow(2.0,2));
if (!CvParamGrid_C.check() || !CvParamGrid_gamma.check())
    cout<<"The grid is NOT VALID."<<endl;
CvSVMParams param;
param.kernel_type = CvSVM::RBF;
param.svm_type = CvSVM::C_SVC;
param.term_crit = cvTermCriteria(CV_TERMCRIT_ITER,100,0.000001);
CvSVM SVM;
SVM.train_auto(trainmat, labelsMat, Mat(), Mat(), param,10, CvParamGrid_C, CvParamGrid_gamma, CvSVM::get_default_grid(CvSVM::P), CvSVM::get_default_grid(CvSVM::NU), CvSVM::get_default_grid(CvSVM::COEF), CvSVM::get_default_grid(CvSVM::DEGREE), true);

cout<<"gamma:"<<param.gamma<<endl;
cout<<"C:"<<param.C<<endl;



return 0;
}
2015-03-02 06:34:59 -0600 received badge  Editor (source)
2015-03-02 06:28:10 -0600 asked a question How to display a single frame from a webcam stream with the press of a key? It's showing assertion failed when I tried to compile the code.
       #include "opencv2/highgui/highgui.hpp" 
       #include <iostream> 
       #include "opencv2/opencv.hpp" 
       using namespace cv; 
       using namespace std; 
        int main(int, char**) 
      { VideoCapture capturo(0); 
      Mat img1, img2; 
      int input; 
      namedWindow("Image 1",CV_WINDOW_AUTOSIZE); 
      namedWindow("Image 2",CV_WINDOW_AUTOSIZE); 
     for(;;){ 
     char input = cvWaitKey(33);
     if(input == 27) break;
     if (input == 49)
    { img1= capturo.grab();
        cv::imshow("Image 1",img1); }
      if (input == 50){ 
      img2= capturo.grab(); 
      cv::imshow("Image 2",img2); } } 
       return 0; }

Please tell what am I doing wrong here. I guess the first few frames is not read so the error is coming up. Can you please give a solution for this?

2015-02-22 08:41:05 -0600 asked a question How to load multiple images using videocapture and then store it in 1D matrices?

I have tried to use the following code to do the above task: Can you say what did I do wrong?

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
VideoCapture cap("/home/bapi/workspace/%03d.jpg");
int img_files= 2;
int img_area=250000;
int k=0;

Mat trainmat(img_files,img_area,CV_32FC1);

Mat image_mat;
Mat gray;

for(;;)
{
cap >> image_mat;
cvtColor(image_mat,gray,CV_BGR2GRAY);
if(gray.empty())

{
cout << "end of sequence" << std::endl;
return -1;
}

int ii=0;

for (int i=0; i<gray.rows; i++)

{
   for (int j=0; j<gray.cols; j++)
{
   trainmat.at<float>(k,ii++) = gray.at<uchar>(i,j);


}

}

k=k+1;
}
cout << trainmat << endl;

}
2015-01-18 04:07:30 -0600 asked a question What is best to use for hand gesture recognition for the mute people?

We are working on a project where we're trying to detect the hand gestures of the mute people. Can you tell the best and the fastest way for that? Is it the canny or using classifiers or background subtraction? Please comment. Your help is much valuable for our team.