Ask Your Question

h_mahmoodian's profile - activity

2017-09-26 07:40:04 -0600 received badge  Notable Question (source)
2016-09-24 05:50:21 -0600 received badge  Popular Question (source)
2015-03-23 04:16:15 -0600 received badge  Student (source)
2015-01-16 05:48:07 -0600 asked a question how can i measure fps for camera?

i use below code for capture video from camera.I do processing ,but i have a problem. I calculate fps but for all frame i see fps=0 and CV_CAP_PROP_FPS=5. how can i calculate fps of my camera?

#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <conio.h>

using namespace cv;
using namespace std;

int main(int, char**)
{
int k=0;
//VideoCapture cap("e:/hassan_1.avi"); // open the default camera
//VideoCapture cap("d:/1.mpg"); // open the default camera
VideoCapture cap(-1);
if(!cap.isOpened())  // check if we succeeded
return -1;
int fps=(float) cap.get(CV_CAP_PROP_FPS)+0.5;
int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
cout<<"total frames ="<<totalframes<<endl;
cout<<"fps= "<<fps<<endl;
getch();
bool stop(false);
Mat edges;
namedWindow("edges",1);
while(!stop)
{
Mat frame;
cap >> frame; // get a new frame from camera
int fps=(int) cap.get(CV_CAP_PROP_FPS)+0.5;
//int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
//cout<<"total frames ="<<totalframes<<endl;
cout<<"fps= "<<fps<<endl;
//double delay=1000/fps;
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);


k++;
//cout<<k<<endl;
//getch();
if (waitKey(10)>=0)
stop= true;
}
cap.release();
cout<<"number of frames that do processing on them= "<<k<<endl;
getch();
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
2015-01-14 10:34:58 -0600 commented question how can i read all frames?

I do not press any key ,but when run my code i see error at 804 th frame

2015-01-14 06:08:09 -0600 commented question how can i read all frames?

i create project in vs2012 with opencv learning name.

2015-01-14 04:37:00 -0600 asked a question how can i read all frames?

I have written some code to read a video and do some processing on it.

int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);

total frames=1707

int fps=(int) cap.get(CV_CAP_PROP_FPS);

fps=30

I do processing on each frame but my code does it for only 804 frames. How can I do the processing for all frames? After processing 804 frames ,i see this text:

Unhandled exception at at 0x75299617 in opencv learning.exe: Microsoft C++ exception: cv::Exception at memory location 0x0041B778.

this is a .avi video format.

Can you please help me to solve this problem? I use windows 7,visual studio 2012,opencv 2.4.6 for processing this video file. my code:

#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <conio.h>

using namespace cv;
using namespace std;

int main(int, char**)
{
int k=0;
VideoCapture cap("f:/video for test/hassan_1.avi"); // open the default camera
if(!cap.isOpened())  // check if we succeeded
  return -1;
bool stop(false);
Mat edges;
namedWindow("edges",1);
while(!stop)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    int fps=(int) cap.get(CV_CAP_PROP_FPS);
    int totalframes=(int) cap.get(CV_CAP_PROP_FRAME_COUNT);
    double delay=1000/fps;
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);


    k++;
    if (waitKey(delay)>=0)
    stop= true;
   }
cap.release();
cout<<"number of frames that do processing on them= "<<k<<endl;
getch();
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
2014-11-10 22:23:42 -0600 asked a question problem with open camera?

i use A4TECH usb camera on my pc. When i run my code i see empty window but when i debug my code (by press F10 key) i can see frame that is captured by camera.How can i fix this problem? i use vs2012,windows 7,OPENCV2.4.6 AND C code

2014-02-13 05:34:06 -0600 commented question how i can add and load data file to train svm classifier?

i use video file c:\happy_0014_1.mpg for test.i want to know add fg-net dataset to program.i have tow fg-net dataset:one of them consists video files and other consists images.i think that i should creat text file and copy dataset images.please help me

2014-02-12 03:29:58 -0600 asked a question how i can add and load data file to train svm classifier?

i read a pdf file that is use FG-NET dataset to train svm. FG-NET Facial Expression and Emotion Database consists of MPEG video files with spontaneous emotions recorded. Database contains examples gathered from 18 subjects ( 9 female and 9 male). Proposed system was trained with captured video frames in which the displayed emotion is very representative. The training set consists of 675 images of seven states neutral and emotional (surprise, fear, disgust, sadness, happiness and anger). inputdir , outputdir,path words that used in this c++ program ,how can i define inputdir,outputdir,path? how i can define path to load dataset for both train and test steps?(ex c:\feed\dataset...) i upload program at:http://rapidshare.com/share/15E45C30BB237A797F355EC82F09B8C1

2014-02-06 00:50:30 -0600 received badge  Editor (source)
2014-02-06 00:46:25 -0600 asked a question how i can load my data set to train classifier in svm?

I work on the Facial Expression Recognition System.when i run program i see this error: C:\fakepath\error.jpg

opencv error:Null pointer (invalid classifier cascade) in unknown function,file c:\slave\builds\WinstallerMegaPack\src\opencv\modules\objdetect\src\haar.cpp,line 1514 C:\slave\builds\WinstallerMegaPack\src\opencv\modules\objdetect\src\haar.cpp,line 1514: error:<-27> Invalid classifier cascade

i think i can not load model correctly for training my system.i have FG-NET dataset to train my system but i do not know add this datasets to my program. What can I type instead of the line marked with stars?

void Demo::processVideo()
{
    CvCapture * capture = cvCaptureFromAVI(this->videofile.c_str());
    cout<<"Loading classifier...."<<endl;
    MultiTrain mt;
    string path = "..\\datasets\\"+type+"\\";        ******
    mt.loadModel((path+"emo_svm_model.xml"));        ******
    int fps = ( int)cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
}

why use "type"?what is type? where is file that is contains model ?(that use in mt.loadmodel()) why we use "emo_svm_model.xml"?

in the other part of my program I use the below code:

void sample(string filename, string type)
{
    CvFont font;
    cvInitFont(&font,0, 1.0f, 1.0f,0,2,8); 
    IplImage *img = cvLoadImage(filename.c_str(), 1);
    MultiTrain mt;
    cout<<"Loading the classifier...."<<endl;
    mt.loadModel("..\\datasets\\"+type+"\\emo_svm_model.xml");******              
    int res = mt.getPrediction(img);
    string result = showResult(res);
    cvPutText(img, result.c_str(), cvPoint(20,20), &font, cvScalar(255,255,0));
    cout<<result<<endl;
    show(img);
    cvReleaseImage(&img);
}

What can I type instead of the line marked with stars? I can not do the training. Please help me to do training.i type multitrain class below: classMultiTrain { public: MultiTrain(); ~MultiTrain(); CvSVM SVM; CvMat *trainData; CvMat *labels; CvTermCriteria criteria; CvSVMParams params; doubleACC; voidcreateDataSet(string inputdir, string outputdir); voidloadDataSet(string filename); voidtrainModel(string outputdir); voidloadModel(string filename); intgetPrediction(IplImage *image); voidtestModel(string filename); voidcreateConfusionMatrix(string filename); voidcalculateTrainDataCount(inttab[]); voidprepareSets(intclass_counts[], intcounts[], intpart, intparts, CvMat *traindata, CvMat *trainlabels, CvMat *testdata, CvMat *testlabels); voidperformCrossValidation(intparts); private: voidprocessData(string path, inti); }; /**cvSeq comparison function**/ static intcomp_func(const void* _a, const void* _b, void* userdata); static intcomp_func_x(const void* _a, const void* _b, void* userdata); endif

i type function that use in multitrain class below: MultiTrain::MultiTrain() { this->trainData = 0; this->labels = 0; this->params = CvSVMParams(); this->params.term_crit.epsilon = 1.0000000116860974e-007; this->params.term_crit.type = CV_TERMCRIT_EPS; this->params.svm_type = CvSVM::C_SVC; this->params.kernel_type = CvSVM::RBF; this->params.gamma = 3.0000000000000001e-006; this->params.C = 20; } MultiTrain::~MultiTrain() { if(this->trainData) cvReleaseMat(&this->trainData); if(this->labels) cvReleaseMat(&this->labels); } voidMultiTrain::createDataSet(string inputdir, string outputdir) { /* 0 neutral 1 happiness 2 sadness 3 surprise 4 anger 5 fear 6 disgust */ vector<string> neutral = vector<string>(); vector<string> happy = vector<string>(); vector<string> sad = vector<string>(); vector<string> surprise = vector<string>(); vector<string> angry = vector<string>(); vector<string> fear = vector<string>(); vector<string> disgust = vector<string>(); listFiles(inputdir, "*neutr*", neutral); listFiles(inputdir, "*happy*", happy); listFiles(inputdir, "*sad*", sad); listFiles(inputdir, "*surpr*", surprise); listFiles(inputdir, "*ang*", angry); listFiles(inputdir, "*fear*", fear); listFiles(inputdir, "*disg*", disgust); intcount = (int)(neutral.size()+happy.size()+sad ... (more)