Ask Your Question

lilouch's profile - activity

2017-07-13 11:28:41 -0600 received badge  Popular Question (source)
2017-07-07 03:03:05 -0600 received badge  Popular Question (source)
2015-01-13 02:20:31 -0600 commented answer background subtraction with a moving camera

how did you do ?

2015-01-12 01:09:31 -0600 received badge  Enthusiast
2015-01-11 10:36:52 -0600 asked a question OpenCV C++ / Multiple histograms on Camshift

I try to improve the initial camshift algorithm by computing lbp (locally binary pattern) histogram and hue distance histogram.

I have some issues about using camshift with those data.

I've already compute the lpb cv::Mat on one hand, and the other hand i computed the hue distance cv::Mat. So at this point i have two features: lbp and hue distance.

Now i would like to compute the two histograms corresponding to each feature but i don't know how to process in order to do that. Indeed in the original camshift there is the calchist function, which take in parameter the HSV picture. Then it computes the histogram with simply hue or hue-saturation histogram.

Do i have to gather those features into one matrix in order to then compute the histogram on it ?

Thank you in advance.

2015-01-08 01:16:56 -0600 commented answer How to make a hue distance histogram ?

Thank again !

2015-01-07 10:40:21 -0600 commented answer How to make a hue distance histogram ?

Thank you for your answer ! Finally i was able to do some stuff but without pointer... I did only:

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

               int val_hue_distance=computeHueDistance(hueChannel.at<uchar>(i,j),val_href);
              hue_distance_mat.at<uchar>(i,j)=val_hue_distance;

        }

retun hue_distance_mat

where ComputeHueDistance is the implementation of the formula which takes in parameters the huechannel image and the Href value i computed before...

It seems very simple in comparison with you, so i don't know if it makes senses what i did.

2015-01-05 02:17:18 -0600 commented answer How to make a hue distance histogram ?

Thank you so much for your answer ! Why do you use pointer ? Is not more simpler to so something like image.at<char>(x,y)? Actually i don't understand those lines

int temp_value_y = abs(img_hsv_ptr[((y-1)img_hsv.cols+3)+(x3)+0] - img_hsv_ptr[((y+1)img_hsv.cols+3)+(x3)+0]); //subtract right pixel from left pixel int temp_value_x = abs(img_hsv_ptr[(yimg_hsv.cols+3)+((x-1)3)+0] - img_hsv_ptr[(yimg_hsv.cols+3)+((x+1)3)+0]);

I suppose you apply the formula ?

But that's true i'm a bit destabilized with the way you do the calculation like : distance_hue_img_ptr[(y*img_hsv.cols)+x]

Thank again

2015-01-05 01:18:56 -0600 received badge  Supporter (source)
2015-01-02 06:06:34 -0600 commented question How to make a hue distance histogram ?

Happy new year ! sorry i don't understand. When i do an histogram i don't use edge detection. Can you explain me again ? Thank you

2014-12-28 06:18:16 -0600 commented question How to make a hue distance histogram ?

I know how to make a histogram based on HUE or saturation value but here it's a histogram based on the distance...And i don't know how to do it

2014-12-26 08:52:58 -0600 asked a question How to make a hue distance histogram ?

Hi,

I would like to improve CamShift algorithm by using a Hue distance histogram. It consists to compute a hue reference Href which is the hue value which has the highest frequency in the histogram h(x) obtained from a region of interest at the step 1 of CAMShift. Then using this Href, we compute the distance like that: image description

I know there is a method called CalcHist in Opencv to compute a histogram, but how i can handle with that ?

Thank you in advance,

2014-12-04 09:12:05 -0600 asked a question C++/OpenCV - Kalman filter for video stabilization

I try to Stabilize video with a Kalman filter for smoothing . But i have some problems

Each time, i have two frames: one current and another one. Here my workflow:

  • Compute goodFeaturesToTrack()
  • Compute Optical Flow using calcOpticalFlowPyrLK()
  • Keep only good points
  • Estimate a rigid transformation
  • Smoothing using Kalman filter
  • Warping of the picture.

But i think there is something wrong with Kalman because at the end my video is still not stabilized and it's not smooth at all, it even worse than the original...

Here my code of Kalman

    cv::Mat StabilizationTestSimple2::computeMask(Mat& frame,int lh,int lw){
    int height=frame.rows;
    int width=frame.cols;

    /// Creation du masque pour le calcul de point d'interet
    int limitH=lh;
    int limitW=lw;
    cv::Mat mask = cv::Mat::zeros(frame.size(), CV_8UC1);  //NOTE: using the type explicitly
    cv::Mat roi1=frame(Range(0,limitH),Range(0,limitW));//Coin haut à gauche
    cv::Mat roi2=frame(Range(height-limitH,height),Range(0,limitW));//Coinbas à gauche
    cv::Mat roi3=frame(Range(0,limitH),Range(width-limitW,width));//Coin haut à droite
    cv::Mat roi4=frame(Range(height-limitH,height),Range(width-limitW,width));//Coin haut à droite

    roi1.copyTo(mask(Range(0,limitH),Range(0,limitW)));
    roi2.copyTo(mask(Range(height-limitH,height),Range(0,limitW)));
    roi3.copyTo(mask(Range(0,limitH),Range(width-limitW,width)));
    roi4.copyTo(mask(Range(height-limitH,height),Range(width-limitW,width)));

    return mask;

}

void StabilizationTestSimple2::init_kalman(double x, double y)
{

    KF.statePre.at<float>(0) = x;
    KF.statePre.at<float>(1) = y;
    KF.statePre.at<float>(2) = 0;
    KF.statePre.at<float>(3) = 0;

    KF.transitionMatrix = *(Mat_<float>(4,4) << 1,0,1,0,    0,1,0,1,     0,0,1,0,   0,0,0,1);
    KF.processNoiseCov = *(Mat_<float>(4,4) << 0.2,0,0.2,0,  0,0.2,0,0.2,  0,0,0.3,0,
                           0,0,0,0.3);
    setIdentity(KF.measurementMatrix);
    setIdentity(KF.processNoiseCov,Scalar::all(1e-6));
    setIdentity(KF.measurementNoiseCov,Scalar::all(1e-1));
    setIdentity(KF.errorCovPost, Scalar::all(.1));
}

and here how i use it. I put only the interesting part. All this code is inside a flor loop. cornerPrev2 and cornerCurr2 contains all the features points detected just before (with calcOpticalFlowPyrLK())

    /// Transformation
    Mat transformMatrix = estimateRigidTransform(cornersPrev2,cornersCurr2 ,false);

    // in rare cases no transform is found. We'll just use the last known good transform.
    if(transformMatrix.data == NULL) {
        last_transformationmatrix.copyTo(transformMatrix);
    }

    transformMatrix.copyTo(last_transformationmatrix);

    // decompose T
    double dx = transformMatrix.at<double>(0,2);
    double dy = transformMatrix.at<double>(1,2);
    double da = atan2(transformMatrix.at<double>(1,0), transformMatrix.at<double>(0,0));

    // Accumulated frame to frame transform
    x += dx;
    y += dy;
    a += da;
    std::cout << "accumulated x,y: (" << x << "," << y << ")" << endl;

    if (compteur==0){
        init_kalman(x,y);
    }
    else {


          vector<Point2f> smooth_feature_point;
          Point2f smooth_feature=kalman_predict_correct(x,y);
          smooth_feature_point.push_back(smooth_feature);
          std::cout << "smooth x,y: (" << smooth_feature.x << "," << smooth_feature.y << ")" << endl;

          // target - current
          double diff_x = smooth_feature.x - x;//
          double diff_y = smooth_feature.y - y;

          dx = dx + diff_x;
          dy = dy + diff_y;

          transformMatrix.at<double>(0,0) = cos(da ...
(more)
2014-12-04 05:30:42 -0600 commented question Smooth point feature trajectories by Kalman Filter in Video Stabilization

@Jenny , are you able to smooth the data ? What do you have in output of Kalman ? Because i would like to smooth the trajectory but there is something wrong...

2014-12-03 03:36:47 -0600 asked a question c++ - Video stabilization pipeline . I certainly missed something

I'm trying to implement a video stabilization. I'm a beginner in this field, but after reviewing lots of post, i chose to do these steps:

Each time, i have two frames: one current and another one, separeted by one frame. Frame 1 and 3, 3 and 5 etc.

  • Compute goodFeaturesToTrack()
  • Compute Optical Flow using calcOpticalFlowPyrLK()
  • Keep only good points
  • Compute the homography using findHomography()
  • Wrap the frame using wrapPerspective()

I certainly missed something because my video is still not stable. I searched on the internet but didn't find a solution. I also saw different posts of stackOverflow like video stabilization using opencv or Video Stabilization with OpenCV

Here my code:

//Read the video
VideoCapture cap(path1);
Mat currImg, colorImg, outImg, grayImg, backupColorImg;


cap.read(colorImg);
VideoUtil::geometricalCrop(colorImg,70,0);//Crop the picture
cvtColor(colorImg,grayImg,CV_BGR2GRAY);
currImg = grayImg.clone();// Current picture


Mat refFrame;
cap.read(refFrame);//Frame +1
VideoUtil::geometricalCrop(refFrame,70,0);
cvtColor(refFrame,refFrame,CV_BGR2GRAY); // Frame +1


namedWindow("Stabilize");
namedWindow("GoodMatches");
Mat temp;
Mat currentFrame=refFrame;
for (;;){
    int nbreCurrentFrame=cap.get(CV_CAP_PROP_POS_FRAMES);//Get the number of current frame
    cap.read(colorImg);

    VideoUtil::geometricalCrop(colorImg,70,0);// Crop the video
    Debug::trace("Current frame: " + to_string(nbreCurrentFrame));
    currentFrame.copyTo(refFrame);//Get the reference frame


    cap.read(colorImg);
    VideoUtil::geometricalCrop(colorImg,70,0);
    cvtColor(colorImg,grayImg,CV_BGR2GRAY);
    currentFrame =  grayImg.clone();//Get the current frame


    vector<Point2f> cornersPrevious;//Stock features of reference Frame
    cornersPrevious.reserve(400);

    vector<Point2f> cornersCurr;//Stock features of current frame
    cornersCurr.reserve(400);

    goodFeaturesToTrack(refFrame,cornersPrevious,400,0.01,5.0);
    Debug::trace("Size of feature track : " + to_string(cornersPrevious.size()));


    vector<uchar> featureFound; // status of tracked features
    featureFound.reserve(400);

    vector<float> featureErrors; // error in tracking
    featureErrors.reserve(400);


    calcOpticalFlowPyrLK(refFrame,currentFrame,cornersPrevious,cornersCurr,featureFound,featureErrors,Size(20,20),3,
                         cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.3),0,0.0001);



    // keep the good points
    std::vector<cv::Point2f> initialPoints;
    std::vector<cv::Point2f> trackedPoints;
    for (int i=0;i<cornersCurr.size();i++){
        double motion = sqrt(pow(cornersPrevious.at(i).x-cornersCurr.at(i).x,2)+pow(cornersPrevious.at(i).y-cornersCurr.at(i).y,2));
        std::cout << "Motion: " << motion << std::endl;
        if (featureFound[i] && motion < 20 ){
            //Keep this point in vector
            initialPoints.push_back(cornersPrevious.at(i));
            trackedPoints.push_back(cornersCurr.at(i));
        }
    }


    // draw the tracking effect
    cv::Mat finalImage;
    currentFrame.copyTo(finalImage);

    // for all tracked points
    for(uint i= 0; i < initialPoints.size(); i++ ) {
        // draw line and circle
        cv::line(finalImage,
                 initialPoints[i], // initial position
                 trackedPoints[i], // new position
                 cv::Scalar(255,255,255));
        cv::circle(finalImage, trackedPoints[i], 3, cv::Scalar(0,0,255),-1);
    }

    //Compute the homography
    if (initialPoints.size() >4 && trackedPoints.size()>4){
        cv::Mat mask;
        cv::Mat transformMatrix = findHomography(initialPoints,trackedPoints,CV_RANSAC,3);


        warpPerspective(refFrame,outImg,transformMatrix,refFrame.size(), INTER_LINEAR |WARP_INVERSE_MAP,BORDER_CONSTANT ,0);
        namedWindow("Stabilized");
       imshow("stabilizedVideo",outImg);
    }


    namedWindow("Tracking features");
    imshow("tracking",finalImage);




    if(waitKey(27) >= 0) break;

}

Thank

2014-12-02 09:32:46 -0600 commented answer video stabilization

@Jenny did you solve your problem ? I had the same, maybe you can help me ? Thank

2014-12-02 09:30:54 -0600 commented answer C++ - Using Bag of Words for matching pictures together?

I finally used BoW with FLANN

2014-12-02 09:29:55 -0600 commented answer C++ - Using Bag of Words for matching pictures together?

I used BoW with FLANN

2014-08-20 03:01:07 -0600 asked a question C++/OpenCV - Why FLANN::index with ORB and LSH works very badly?

I'm looking for a picture inside a database (1000 pictures). In order to do that, i use Bag of Features with ORB. Then, i use LSH.

There is something i don't understand at all. With KD-TREE i got among my 3 nearest neighbor one good match then, the other results are very bad. I think it's because KD-TREE works very badly in highly dimentional data.

Index : [47, 194, 1118] Dist : [0, 0.01984383, 0.021690277]

Then when i use LSH with hamming distance, i always get the same bad results results whatever my query image.

Index : [0, 1, 2] Dist : [0, 0, 0]

 responseDatabase.convertTo(responseDatabase,CV_8U);
 cv::flann::Index flannIndex(responseDatabase,cv::flann::LshIndexParams(20,10,2), cvflann::FLANN_DIST_HAMMING);
cv::Mat results, dists;
 int k=3; // find the 3 nearest neighbors


// search (nearest neighbor)
responseQuery.convertTo(responseQuery,CV_8U);
flannIndex.knnSearch(responseQuery, results, dists, k, cv::flann::SearchParams() );

and

 cv::flann::Index flannIndex(responseDatabase,cv::flann::KDTreeIndexParams,cvflann::FLANN_DIST_EUCLIDEAN);
cv::Mat results, dists;
 int k=3; // find the 3 nearest neighbors


// search (nearest neighbor)
flannIndex.knnSearch(responseQuery, results, dists, k, cv::flann::SearchParams() );

responseQuery --> cv::Mat which contains the response histogram of the query databaseQuery --> cv::Mat which contains the response histogram of all my pictures of my database

Do i miss something ? Maybe with ORB there is something i have to do besides the others things ? I precise that firstly i used SIFT and SURF with LSH and KD-TREE and i got pretty good results even if it was not perfect.

Can anyone explain me why ? I really don't understand why.

However i use BruteForce-Hamming as a matcher.

2014-08-20 03:00:08 -0600 commented question C++/OpenCV - How can i get my image after using flann::index? (With BoF)

Yes this is what i did. Simply. But i don't know if it was the best way. Anyway thank !

2014-08-19 05:32:18 -0600 commented question C++/OpenCV - How can i get my image after using flann::index? (With BoF)

Yes i know but the responseDatabase correspond to histograms and not the picture ! I would like to display the picture corresponding to this histogram...Do you know ?

2014-08-19 05:20:12 -0600 asked a question C++/OpenCV - How can i get my image after using flann::index? (With BoF)

I use BoW with SURF and FlannBasedMatcher for image retrieval inside a database. I extracted all my features of my database (Training) using SURF , then i builded the vocabulary and finally i got the BOF frequency histograms for each pictures inside my database (training).

to be clear, i don't put the details of all of this process but tell me if you need some details.

So at this step i have :

  • cv::Mat allDescriptors --> descriptors of my all database (training)

  • cv::Mat Vocabulary --> codebook representation

  • cv::Mat responseDatabase --> frequency histograms for each pictures inside my database

Then i used a query and compute its reponse according to the vocabulary computed just before. Finally i have this data :

  • cv::Mat responseQuery --> frequency histogram of my query

Now i have some difficulties. I used

 cv::flann::Index flannIndex(responseDatabase, cv::flann::KDTreeIndexParams(), cvflann::FLANN_DIST_EUCLIDEAN);
cv::Mat results, dists;
int k=2;
flannIndex.knnSearch(responseQuery, results, dists, k, cv::flann::SearchParams() );

It worked well and i got this results :

  • cv::Mat results --> [38, 117]

  • cv::Mat dist --> [0.0010655867, 0.013091294]

But now with those results, how can i recover the two pictures corresponding to my 2 nearest neighbors ? Indeed, i don't have any trace of the pictures inside each of my data.

Maybe, i missed one step but which one ?

Thank

2014-08-18 05:10:09 -0600 asked a question How to build an index of a database for image retrieval ?

I would like to use BoW with FLANN in order to index all my pictures inside my database.(For a CBIR project)

What i did :

  1. Loop over all ma database in order to compute the descriptors of each pictures.
  2. Clustering descriptors using K-MEAN
  3. Extraction of BoWDescriptors (Visual words) in order to have a big histogram with all my features
  4. Use FLANN Index to compute an index in each pictures

Code:

// Create Flann LSH index
cv::flann::Index flannIndex(this->descDescriptorbow, cv::flann::LshIndexParams(12, 20, 2), cvflann::FLANN_DIST_HAMMING);

cv::Mat results, dists;

int k=2; // find the 2 nearest neighbors

// search (nearest neighbor)
flannIndex.knnSearch(responseHist, results, dists, k, cv::flann::SearchParams() );

DescriptorBow contains all my BoWfeatures of my database. ResponseHist constains all my BoWfeatures of my folder which contains the test database (Some pictures to evaluate in order to find the nearest neighbor).

but i got an error

OpenCV Error: Bad argument (Only continuous arrays are supported) in buildIndex_, file /home/samoun/Bureau/opencv-2.4.6.1/modules/flann/src/miniflann.cpp, line 317 terminate called after throwing an instance of 'cv::Exception' what(): /home//opencv-2.4.6.1/modules/flann/src/miniflann.cpp:317: error: (-5) Only continuous arrays are supported in function buildIndex_

In order to see the structure of my cv::Mat descDescriptorbow i used

    ofstream compute_info("info.txt", ios::out | ios::trunc);
//responseVector = responseHist.reshape(0,1);
 compute_info << descDescriptorbow << std::endl;
 compute_info.close();

Indeed in my file.txt which contains the boWFeatures,it's not a continious array.

So i don't know if if did well or i missed a step ?

Maybe do you know a tutorial step-by-step because i'm a bit lost ?

Can someone help me ?

2014-08-08 02:29:47 -0600 commented answer C++ - Using Bag of Words for matching pictures together?

Thank for your answer. The problem is i can't use SIFT or SURF because they are patented. So i used ORB with BoW but yeah it's not good as SIFT or SURF. I get a bit confusing because some people told me that BoW is for classificatino ( i agree) but other told me that i can use for matching but i don't know how because i have more than 2000 differents pictures so it assumes that i have to have 2000 class ?

2014-07-17 07:35:07 -0600 commented answer C++ / mean of value CvSVM::predict()

I understood what you told me but i follow a tutorial when they say that the code i used is for image classification with lots of classes...Therefore i'm a bit lost. I follow this trame : 1. Obtain the set of bags of features. Select a large set of images. Extract the SIFT feature points of all the images in the set and obtain the SIFT descriptor for each feature point that is extracted from each image. Cluster the set of feature descriptors for the amount of bags we defined and train the bags with clustered feature descriptors (we can use the K-Means algorithm). Obtain the visual vocabulary. Therefore it's cluster the 4 classes no ? Maybe i'm mistaken...

Otherwise, how can i do a 1 vs all classifier for each class or make a classifier for each combination of 2 class please ?

2014-07-17 06:55:05 -0600 asked a question C++ / mean of value CvSVM::predict()

I'm actually working on a project of logos classification using SURF + BOW + SVM. This is my first time i'm work on a kind of project and especially with SVM.

So i have two folders : train and eval which contains 4 classes of differents elements.My class are distinctive because i have a class of boat,class of car,class of plane and class of animals. Train has about 255 pictures (so 255/4) Eval has about 340 pictures (so 340/4)

I followed a tutorial which explain how use BoW. I think that's fine for me but i have a problem with the value of my svm.predict().

for (int i=0;i<logos_list_eval.size();i++){
      cv::Mat imgEval=cv::imread(path_to_eval + logos_list_eval.at(i),CV_LOAD_IMAGE_GRAYSCALE);
      ssm_ensure(imgEval.data, "Could not load the first image");
      //Debug::info("Eval : " + logos_list_eval.at(i));
      detector_training.detect(imgEval, keypoint2);
      bowDE.compute(imgEval, keypoint2, bowDescriptor2);

      evalData.push_back(bowDescriptor2);
      groundTruth.push_back((float) i);
      float response = svm.predict(bowDescriptor2);
      std::cout << "Reponse : " << response <<  std::endl;
      results.push_back(response);
      string info= logos_list_eval.at(i) + " |  response : " + convertInt(response) ;
      compute_info << info << std::endl;

  }

The result of my prediction is :

... Reponse : 242 Reponse : 242 Reponse : 178 Reponse : 242 Reponse : 178 Reponse : 175 Reponse : 121 Reponse : 190 Reponse : 191 Reponse : 186 Reponse : 188 Reponse : 207 Reponse : 189 Reponse : 189 Reponse : 179 Reponse : 178 Reponse : 201 Reponse : 173 Reponse : 188 Reponse : 178 Reponse : 179 Reponse : 186 Reponse : 189 Reponse : 189 Reponse : 189 Reponse : 209 Reponse : 178 Reponse : 179 ...

I don't understand theses values. How can i know if it's belong to class 1,2,3 or 4 ?

2014-07-09 07:31:16 -0600 commented answer C++ - Using Bag of Words for matching pictures together?

okey but i don't understand something. you told me that Bow doesn't work well with orientated objects but however in this algorithm local feature with descriptors are extracted. So in the picture above, Let's assume the eye is considered as a feature extrated by the BoW, if it's rotated or not, it's changing anything no ? So if's with the rotation it doesn't work well, are there others algorithms that can be work well on my case ? Because i would like something light to compute (As you told me,make a comparison of keypoints with thousands of images will be very heavy and long process...)

2014-07-09 07:12:08 -0600 commented answer C++ - Using Bag of Words for matching pictures together?

Thank you for your answer ! i've already read this document. So you advise to me to implement BoW ? It's a good approach ?

2014-07-09 06:03:51 -0600 received badge  Student (source)
2014-07-09 05:15:58 -0600 asked a question C++ - Using Bag of Words for matching pictures together?

I would like to compare a picture (with his descriptors) with thousand of pictures inside a database in order to do a matching. (if two pictures are the same,that is to say the same thing but it can bo rotated, a bit blured, has a different scale etc.).

For example, in this case there is a matching ( i've used SIFT with a robust matcher :

image description

I saw on the internet that compute descriptors for each picture and compare them one to one is very a long process. I did some researches and i saw that i can do an algorithm based on Bag of Words.

I don't know exactly how is works yet, but it seems to be good. But in think, i can be mistaked, it is only to detect what kind of object is it not ?

I would like to know according to you if using it can be a good solution to compare a picture to a thousands of pictures using descriptors like Sift of Surf ?

If yes, do you have some suggestions about how i can do that ?

Thank,

2014-01-17 03:35:50 -0600 asked a question Calchist for RGB histogram on my frame

I have a frame with a define area and i want to calcul the histogram of it. I don't know how to do this. i want to use calchist but this function need a mask and for a mask i use inRange but is it necessary ? Because i just want to have a histogramme of my area using calcHist.

2014-01-16 03:44:18 -0600 received badge  Editor (source)
2014-01-16 03:27:23 -0600 asked a question Define a fix area in Meanshift

Hi everyone,

I need your help in OpenCV. I'm a student and i actually work in a project which consist to have a little autonomous car. I use Python for the main language programming.

I have some problem with my meanshift. I want when i run the program that the camera fix a area on the floor and stay on this area. Because i would like that the car drive alone following the floor and i don't want that meanshift find another object different from the floor. So the program works well but not optimally for the floor... Have you got a solution or a way to proceed ? (Sorry if my english is not so good)

Thank you !