Ask Your Question

user1234's profile - activity

2018-03-01 12:16:43 -0600 received badge  Notable Question (source)
2017-11-12 12:50:51 -0600 received badge  Popular Question (source)
2017-02-01 12:46:30 -0600 received badge  Popular Question (source)
2015-07-14 07:53:58 -0600 commented question Best practice for CUDA streams --> How to get OpenCV GPU module to work asynchronously??

@Wolf: Could you please share the solution of the above problem. I am also working on a similar problem where I have multi-threading. One thread captures the image and other 2 threads process the image using their own streams. But the computational time has not reduced. Please share the approach you followed to solve the above situation.

2014-02-05 13:21:44 -0600 asked a question Negative values for the feature coordinates obtained using goodFeaturesToTrack() in opencv

I am finding the feature points using goodFeatureToTrack() in opencv. But when i checked the coordinates(x,y) of the obtained features, i found that some of them are negative.

How is it possible that feature coordinates are negative. My partial code is below;

goodFeaturesToTrack( frame1, cornersFrame1, maxCorners, qualityLevel, minDistance, Mat(), blockSize, useHarrisDetector, k ); 

for(int i=0; i<cornersFrame1.size(); i++)
{
    int row = (int)cornersFrame1[i].y;
    int col = (int)cornersFrame1[i].x;  
    cout<<"\n cooridnates:  ("<<row<<" , "<<col<<"  )";
}
2014-02-02 12:09:32 -0600 asked a question getting an error for "OpponentColorDescriptorExtractor" in opencv

I want to have the descriptor for keypoints with color information. so, i want to use "OpponentColorDescriptorExtractor" as mentioned here:

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_extractors.html#opponentcolordescriptorextractor

I am using the following code but i am getting an error:

The following code is working:

SiftDescriptorExtractor detector;   
Ptr<DescriptorExtractor> oppDescExtractor;

OpponentColorDescriptorExtractor opponentDescExtractor(oppDescExtractor);

The error is:

OpenCV Error: Assertion failed (!descriptorExtractor.empty()) in OpponentColorDescriptorExtractor,

So, how should i declare "OpponentColorDescriptorExtractor" ?

2014-02-01 08:24:30 -0600 received badge  Scholar (source)
2014-02-01 08:24:27 -0600 received badge  Supporter (source)
2014-02-01 05:26:04 -0600 asked a question How to know the datatype of a input image?

I am reading an image from my computer and i want to know the datatype of that image. How can i do so?

The input image could be...CV_8UC1, CV_32FC1 or any other possibility.

Mat input = imread("sample.jpg", 1);
2014-01-30 10:54:53 -0600 received badge  Editor (source)
2014-01-30 10:51:45 -0600 asked a question Extracting the Percentage of color (Red,blue,green,yellow,orange) in an image in Opencv?

I have to differentiate between 5 types of images which could have mostly either red,green, blue, orange or yellow color with some white or black color. I have to find which color is prominent in the image.

The source of images is Webcam, so the actual color also depends upon the illumination and distance of the image from webcam.

I am trying to calculate the percentage based upon "Hue" values. I am specifying some range for each color. My ranges are:

Red: 0-10
Green: 50-65

Yellow: 18-21

Blue: 100-115

PROBLEM: Even though the image displayed is not Red still i am getting high % for red color.

My code is following:

int findRect::checkByHSV(int svmResult, Mat detectedSquare)
{

    Mat hsv_img;
    cvtColor(detectedSquare,hsv_img,CV_BGR2HSV);

    Vec3b pixel;
    float totalPixel=0; // to count the total number of pixels in an image---to get the Percentage later
    float totalClass[6];// because we want to test for 5 classes + a garbage class.{{ Class-0 -> Garbage, Class-1->Orange, Class-2->Green, Class-3->Red, 
                        //  Class-4->Blue, Class-5->Yellow }} 

    for(int i=0; i<hsv_img.rows; i++)
    {
        for (int j=0; j<hsv_img.cols; j++)
        {

            totalPixel++;
            pixel= hsv_img.at<Vec3b>(i,j);

            if(  pixel[0]>0 &&  pixel[0]<1  )           totalClass[1]++;    // Class-1->Orange
            else if (  pixel[0]>50 &&  pixel[0]<65  )   totalClass[2]++;    // To check Green class-2 //svmResult==2 && 
            else if (  pixel[0]>0 &&  pixel[0]<10  )        totalClass[3]++;    // Class-3->Red
            else if (  pixel[0]>100 &&  pixel[0]<115  )     totalClass[4]++;    // Class-4->Blue
            else if (  pixel[0]>18 &&  pixel[0]<21  )       totalClass[5]++;    // Class-5->Yellow
        }

    }

    float percentage[5];
    totalClass[0]=0; //Putting zero to the Garbage class

    for (int i=0; i<=5; i++)
    {
        percentage[i] = (totalClass[i] / totalPixel )*100;
    }

    cout<<"\n Organge: "<<percentage[1]<<"  Green: "<<percentage[2]<<"  Red: "<<percentage[3]<<"  Blue: "<<percentage[4]<<"  Yellow: "<<percentage[5]<<"\n \n";

    return svmResult;
}
2014-01-27 14:17:07 -0600 commented question How to remove the CvSeq points which results in overlapping Squares/rectangles in opencv?

@berak: Ok, thanks i will try to find something related to it :)

2014-01-27 13:52:21 -0600 commented question How to remove the CvSeq points which results in overlapping Squares/rectangles in opencv?

@berak: ok, but any suggestion about if the two CvSeq are overlapping or not?

2014-01-27 13:44:04 -0600 asked a question How to remove the CvSeq points which results in overlapping Squares/rectangles in opencv?

I am able to detect all the squares/rectangles (any contour consists of 4 points) in a given WEBCAM frame. But i am facing a problem that it detects a single square/rectangle as 3-4 squares/rectangles which covers more or less the same portion of the image (Not exactly the same).

Problem: I want to remove those CvSeq which give me the similar "square" which has already been processed/drawn.

The part of my code where i am trying to draw the squares after receiving the information about all the squares contained in CvSeq is following:

// the function draws all the squares in the image
void drawSquares( IplImage* img, CvSeq* squares ) // CvSeq* squares--> "square" contains all the points for all the squares.
{

    CvSeqReader reader;
    IplImage* cpy = cvCloneImage( img );
    int i;    


    // initialize reader of the sequence
    cvStartReadSeq( squares, &reader, 0 );

    // read 4 sequence elements at a time (all vertices of a square)
    for( i = 0; i < squares->total; i += 4 ) // increaing i by 4 because one square consists of 4 points
    {
        CvPoint pt[4], *rect = pt;
        int count = 4;

        // read 4 vertices
        CV_READ_SEQ_ELEM( pt[0], reader );
        CV_READ_SEQ_ELEM( pt[1], reader );
        CV_READ_SEQ_ELEM( pt[2], reader );
        CV_READ_SEQ_ELEM( pt[3], reader );

        // draw the square as a closed polyline
        cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );

    }

    // show the resultant image
    cvShowImage( wndname, cpy );
    cvReleaseImage( &cpy );
}
2014-01-24 06:03:42 -0600 asked a question Setting Vocabulary in creating "Bag of features" to do SVM classification

I am trying to do 3-class classification using SVM. For that, i am preparing vocabulary during the SVM training. But as i am getting random results during SVM prediction, so i suspect that there is some problem in my vocabulary creation method. My code to create vocabulary is following:

//Mat train --- it should contain the feature vectors
//Mat response-- it will contain the class labels

void svm::createTrainingDateUsingBOW(int flag,Mat& train, Mat& response, int label)
{

    int cluster = 9; // Common for all classes  
    cv::Mat imageForTraining;
    std::vector<cv::KeyPoint> keypoints; 
    cv::SurfFeatureDetector detector(500);
    cv::Ptr<cv::DescriptorExtractor> cvDescExt = new cv::SurfDescriptorExtractor();
    cv::Mat descriptors; 

    cv::BOWKMeansTrainer bow(cluster, cv::TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, FLT_EPSILON), 1, cv::KMEANS_PP_CENTERS);
    cv::Mat vocabulary; 

    if (flag == 1)
    {
        for(int i=1; i<=400; i++)
        {
            counter++;
            cout<<"\n counter:  "<<counter;

            char filepath[255];
            sprintf(filepath, "class1/%d.JPG",i); // we need class1/1.JPG etc

            imageForTraining = cv::imread(filepath, CV_LOAD_IMAGE_GRAYSCALE);

            // Preparing keypoints using detector
            detector.detect(imageForTraining, keypoints);

            // now getting the DESCRIPTORS for the given keypoints
            cvDescExt->compute(imageForTraining, keypoints, descriptors);

            //BOW
            if(keypoints.size() > cluster)  // so that (N<k) error won't come
            {
                if (!descriptors.empty()) bow.add(descriptors); 

                //VOCABULARY
                vocabulary = bow.cluster();

                cv::Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();
                cv::Ptr<DescriptorMatcher> matcher = cv::DescriptorMatcher::create("FlannBased");
                cv::BOWImgDescriptorExtractor descExtractor (extractor, matcher);

                descExtractor.setVocabulary(vocabulary); 
                Mat bowDescriptors; 
                descExtractor.compute(imageForTraining, keypoints, bowDescriptors); 
                if ( !bowDescriptors.empty())
                {
                    train.push_back(bowDescriptors);
                    response.push_back(label);
                }

            }// ending if loop

        } // ending For loop    
    }// ending if(flag ) loop


    if (flag == 2)
    {
        for(int i=1; i<=400; i++)
        {
            counter++;
            cout<<"\n counter:  "<<counter;

            char filepath[255];
            sprintf(filepath, "class2/%d.JPG",i); // we need class1/1.JPG etc

            imageForTraining = cv::imread(filepath, CV_LOAD_IMAGE_GRAYSCALE);

            // Preparing keypoints using detector
            detector.detect(imageForTraining, keypoints);

            // now getting the DESCRIPTORS for the given keypoints
            cvDescExt->compute(imageForTraining, keypoints, descriptors);

            //BOW
            if(keypoints.size() > cluster)  // so that (N<k) error won't come
            {
                if (!descriptors.empty()) bow.add(descriptors); 

                //VOCABULARY
                vocabulary = bow.cluster();

                cv::Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();
                cv::Ptr<DescriptorMatcher> matcher = cv::DescriptorMatcher::create("FlannBased");
                cv::BOWImgDescriptorExtractor descExtractor (extractor, matcher);

                descExtractor.setVocabulary(vocabulary); 
                Mat bowDescriptors; 
                descExtractor.compute(imageForTraining, keypoints, bowDescriptors); 
                if ( !bowDescriptors.empty())
                {
                    train.push_back(bowDescriptors);
                    response.push_back(label);
                }

            }// ending if loop

        } // ending For loop    
    }// ending if(flag ) loop

....Similary for Class-3

}
2013-12-17 13:26:17 -0600 answered a question How to 2-Class Categolization using SURF+BoW+SVM

@shinge: in your svmPredict() , you are using svm.predict(centroids, true); but you have not created centroids anywhere in the code. Can you please tell me, how to have that centroids ?

2013-12-17 13:25:00 -0600 commented answer How to 2-Class Categolization using SURF+BoW+SVM

@shinge: in your "svmPredict()" , you are using "svm.predict(centroids, true);" but you have not created "centroids" anywhere in the code. Can you please tell me, how to have that "centroids" ?

2013-12-08 04:38:48 -0600 answered a question How to 2-Class Categolization using SURF+BoW+SVM

Hello, i need some suggestion regarding SVM. I have to detect Hazardous Material sign which are generally square shape. So, using SVM i want to know whether in the given frame any such sign is present or not...and what is the location of that hazMat sign if it present. So, can SVM really solve my purpose of finding the location of HazMat sign?