Ask Your Question

ahmad_asadi's profile - activity

2016-08-02 08:35:38 -0600 received badge  Editor (source)
2016-08-02 08:23:57 -0600 commented question PCA returns NaN

In addition, transposing data_training_mat tends to appearance of some small numbers inside a bunch of NaNs and Infs in eigenvalues, if it clarifies some points!

2016-08-02 08:13:38 -0600 commented question PCA returns NaN

I check eigenvalues after that. All values are -NaN:

Mat average = Mat();
PCA pca(training_data_mat, average, CV_PCA_DATA_AS_ROW);

cout << "checking pca... " << endl ;
cout << pca.eigenvalues << endl ;
2016-08-02 08:03:42 -0600 commented question PCA returns NaN

hog_ders is right now the vector of image histogram not HOG descriptors. However, converting the type to CV_32F does not change anything.

2016-08-02 07:55:51 -0600 asked a question PCA returns NaN

Hi everybody,

I'm attempting to classify 10 classes of hand pictures using a specific feature space. Training data is converted to a Mat object containing 240 rows (number of training pictures) and 480 cols (number of features) normalized between 0 and 1. The type of training data mat is CV_64FC1. I'm going to pass this matrix to PCA in order to extract useful features. After that I want to pass PCA result to SVM in order to train a classifier.

The PCA object returns all -NaN and Inf after creating the object:

PCA pca(training_data_mat, Mat(), CV_PCA_DATA_AS_ROW);

training_data_mat is the matrix of the training data with 240 rows and 450 cols for 240 training images and 450 features. It is created in the following line:

training_data_mat.push_back(extract_features_mat(descriptor,hog_ders)) ;

the extract_features_mat function is written such that returns a 1 row Mat of type CV_64FC1 containing features of the image. The following line is return value of the extract_features_mat function:

return Mat (1,feature_size, CV_64FC1, feature_value) ;

and feature_value is a double array defined and filled in this function.

I'm totally confused what is wrong!

This is my extract_features_mat function:

Mat extract_features_mat(Mat descriptor, std::vector<float> hog_ders)
{
        int feature_size = descriptor.cols + hog_ders.size() ;
        double feature_value[feature_size] ;
        double gamma = 0.05 ;
        for(int j = 0 ; j < descriptor.cols ; j++)
        {
            feature_value[j] = 0 ;
            for(int h = 0 ; h < descriptor.rows ; h++)
            {
                double to_be_added_value = (descriptor.at<double>(h,j)/pow(10,15) ) ;
                feature_value[j] += to_be_added_value;
                if(feature_value[j] > 1)
                    feature_value[j] = 1 ;
            }   
        }

        float max = 0 ;
        for(int j = 0 ; j < descriptor.cols ; j++)
        {
            if(feature_value[j] < 0.1 )
                feature_value[j] = 0.1 ;
            feature_value[j] = 1 * pow(feature_value[j],gamma) ;
            if(max < feature_value[j])
                max = feature_value[j] ;
        }

        for(int j =0 ; j < descriptor.cols ; j++)
            feature_value[j] = feature_value[j] / max ; 
        max = 0 ;
        for(int j = descriptor.cols ; j < descriptor.cols + hog_ders.size() ; j++)
        {
            feature_value[j] = hog_ders.at(j - descriptor.cols) ;
            if(max < feature_value[j])
                max = feature_value[j] ;
        }   
        for(int j = descriptor.cols ; j < descriptor.cols + hog_ders.size() ; j++)
            feature_value[j] = feature_value[j] / max ; 

        return Mat(1,feature_size, CV_64FC1, feature_value) ;
}
2016-07-22 04:10:59 -0600 commented question Segmentation fault on cv::imshow function

I have changed that and everything is working good! Thanks a lot berak!

2016-07-22 03:44:43 -0600 asked a question Segmentation fault on cv::imshow function

Hello every one, here is my function "optical_flow_using_schunck". on line "imshow("frame1", frame1)" it throws "Segmentation fault (Core dumped)" error.

Any idea?!

int optical_flow_using_schunck(char * video_url)
{
    int iteration_count = 20 ;
    double a = 0.001 ;

    namedWindow("frame1" , CV_WINDOW_AUTOSIZE) ;
    namedWindow("frame2" , CV_WINDOW_AUTOSIZE) ;

    cout << "Analyzing motion using Schunck approach for approximating optical flow..." << endl ;
    cout << "Reading video from " << video_url << endl ;
    VideoCapture vid (video_url);
    if(!vid.isOpened())
    {   
        cout << "An error has been occured. The video can not be opened!" << endl ;
        return -1 ;
    }

    Mat frame1, frame2 ;
    vid >> frame1 ;
    if(!frame1.empty())
        vid >> frame2 ;

    cvtColor(frame1 , frame1 , CV_BGR2GRAY) ;
    cvtColor(frame2 , frame2 , CV_BGR2GRAY) ;

    pyrDown(frame1, frame1, Size(frame1.cols/2, frame1.rows/2)) ;
    pyrDown(frame2, frame2, Size(frame2.cols/2, frame2.rows/2)) ;

    cout <<"initializing velocity to zero" << endl ;

    int sz[] = {frame1.rows, frame1.cols};
    Mat u(2, sz, CV_32FC1, Scalar::all(0));
    Mat v(2, sz, CV_32FC1, Scalar::all(0));
    Mat u_avg(2, sz, CV_32FC1, Scalar::all(0));
    Mat v_avg(2, sz, CV_32FC1, Scalar::all(0));
    Mat Ex(2, sz, CV_32FC1, Scalar::all(0));
    Mat Ey(2, sz, CV_32FC1, Scalar::all(0));
    Mat Et(2, sz, CV_32FC1, Scalar::all(0));

    while(!frame2.empty())
    {
        cout << "calculating Ex derivative..." << endl ;
        calculate_EX(frame1, frame2, &Ex) ;
        cout << "calculating Ey derivative..." << endl ;
        calculate_EY(frame1, frame2, &Ey) ;
        cout << "calculating Et derivative..." << endl ;
        calculate_ET(frame1, frame2, &Et) ;

        if(frame1.empty())
            cout << "WOW!" << endl ;
        imshow("frame1" , frame1) ;
        imshow("frame2" , frame2) ;

        for(int iter = 0 ; iter < iteration_count ; iter ++)
        {
            cout << "iteration: " << iter << endl ;

            for(int i = 0 ; i < u.rows ; i ++)
            {
                for(int j = 0 ; j < u.cols ; j++)
                {
//                  cout << "i: " << i << ", j:" << j << endl;  
                    double common_part = (Ex.at<double>(i,j)*u_avg.at<double>(i,j) + Ey.at<double>(i,j) * v_avg.at<double>(i,j) + Et.at<double>(i,j) ) / (pow(a,2) + pow(Ex.at<double>(i,j),2) + pow(Ey.at<double>(i,j),2) ) ;
                    double delta_u = ( Ex.at<double>(i,j) * common_part) ;
                    double delta_v = ( Ey.at<double>(i,j) * common_part) ;
                    u.at<double>(i,j) = u_avg.at<double>(i,j) - delta_u ; 
                    v.at<double>(i,j) = u_avg.at<double>(i,j) - delta_v ;
                }
            }

            // cout << "u_avg is being updated"<< endl ;
            update_veloc_avg(u, &u_avg) ;
            // cout << "u_avg has been updated"<< endl ;
            update_veloc_avg(v, &v_avg) ;
            // cout << "v_avg has been updated"<< endl ;

            // imshow("U_veloc" , u) ;
            // imshow("V_veloc" , v) ;
            // waitKey(0) ;
        }
                        cout << "6" << endl ;
        frame2.copyTo(frame1(Rect(0, 0, frame2.cols, frame2.rows)));
                        cout << "7" << endl ;
        vid >> frame2 ;
                        cout << "8" << endl ;
        cvtColor(frame2 , frame2 , CV_BGR2GRAY) ;
                        cout << "9" << endl ;
        pyrDown(frame2, frame2, Size(frame2.cols/2, frame2.rows/2)) ;
                        cout << "10" << endl ;
        waitKey(0) ;
    }
    cout << "**************************************************\nSchunk ego motion estimation.\n\n\tTHE VIDEO FINISHED\n**************************************************\n" << endl ;
}

here are my other functions "calculate_Ex", "calculate_Ey" , "calculate_Et" and "update_veloc_avg" .

void calculate_EX(Mat frame1, Mat frame2, Mat *E) 
{
    for(int i = 0 ; i < E->rows ; i++)
    {
        for(int j = 0 ; j < E->cols ; j++)
        {
            double res = 0 - (frame1.at<double>(i,j) + frame2.at<double>(i,j)) ;

            if(j < frame1.cols - 1)
                res += frame1.at<double>(i,j+1) ;
            if(j < frame1.cols - 1 && i < frame1.rows - 1)
                res += frame1.at<double ...
(more)
2016-04-18 13:03:03 -0600 received badge  Student (source)
2016-04-06 10:52:25 -0600 asked a question histogram smoothing

I have an image in RGB, along with its planes' histograms. How I can smooth these histograms?

(histograms are generated using opencv calcHist function)