Ask Your Question

guidovitale's profile - activity

2017-08-22 16:22:15 -0500 received badge  Nice Answer (source)
2017-04-04 07:50:50 -0500 received badge  Teacher (source)
2017-04-04 03:39:12 -0500 received badge  Self-Learner (source)
2017-04-04 03:02:10 -0500 answered a question Downhill Solver -- error due to pure virtual functions

thanks berak. I will post my small code as an hint for those, like me, are novice to opencv.

// Qt stuff
    #include "mainwindow.h"
    #include <QApplication>

// OpenCV libraries 
    #include <opencv2/opencv.hpp>
    #include "opencv2/core/utility.hpp"
    #include "opencv2/highgui.hpp"

    #include "opencv2/core/core_c.h"
    #include "opencv2/core/cvdef.h"
    #include "opencv2/core/optim.hpp"

    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>

    using namespace cv;
    using namespace std;




    class DistanceToLines :public MinProblemSolver::Function
    {
    public:
// quadratic functional to minimize (f(x1,x2) = x1^2 + x2^2)
        double calc(const double* x)const
        {
            return x[0] * x[0] + x[1] * x[1];
        }
// nb of degrees of freedom (i.e. how many unknowns)
        int getDims() const
        {
            return 2;
        }
    };



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

        QApplication a(argc, argv);


        // create a nelder-mead simplex solver
        Ptr<DownhillSolver> DHS = DownhillSolver::create();

        // function to minimize
        Ptr<MinProblemSolver::Function> ptr_F(new DistanceToLines());

        // init guess
        Mat P = (Mat_<double>(1, 2) << 1.0, 1.0);
        DHS->setFunction(ptr_F);

        // init step
        Mat step = (Mat_<double>(2, 1) << -0.5, 0.5);
        DHS->setInitStep(step);

        // solve the preoblem
        double res = DHS->minimize(P);

        // output reidual
        cout << "res " << res << endl;


        return 0;

    }

I'm using opencv with qt on a win10 machine, compiling with mingw.

2017-03-30 07:05:23 -0500 received badge  Student (source)
2017-03-30 04:33:23 -0500 commented answer Downhill Solver -- error due to pure virtual functions

Thank you, Berak. the code is now working. couldnt post it as a comment since it's too long. btw, I'm using opencv 3.0.0 with qt and mingw as a compiler on a win10 machine

2017-03-30 03:44:44 -0500 received badge  Editor (source)
2017-03-30 03:29:52 -0500 asked a question Downhill Solver -- error due to pure virtual functions

I'm familiarizing with Optimization Algorithm in OpenCV. I've found an interesting example to start with:

http://answers.opencv.org/question/33...

so, I developed some code based on that:

#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace cv;
using namespace std;


class DistanceToLines :public MinProblemSolver::Function
{
public:
    double calc(const double* x)const
    {

        return x[0] * x[0] + x[1] * x[1];
    }
};


int main()
{

    Ptr<DownhillSolver> DHS = DownhillSolver::create();


//    Ptr<MinProblemSolver::Function> ptr_F = makePtr<DistanceToLines>();  // NOT WORKING!!!
    Ptr<MinProblemSolver::Function> ptr_F(new DistanceToLines());                // NOT WORKING!!!

    return 0;

}

It gives me the following error, when building:

D:\ALGORITMI\minDownhill\main.cpp:50: error: invalid new-expression of abstract class type 'DistanceToLines'
     Ptr<MinProblemSolver::Function> ptr_F(new DistanceToLines());
D:\ALGORITMI\minDownhill\main.cpp:33: note:   because the following virtual functions are pure within 'DistanceToLines':
 class DistanceToLines :public MinProblemSolver::Function

any hint? I saw that there are not many examples on the web about these methods, so I cannot figure out what is happening.

2017-03-29 06:32:38 -0500 commented answer getting score and raw data of each circle with CvHoughCircles

sorry for the post, did not notice the policy you are talking about; I'll remove the answer if you prefer.

btw, why this huge downvote? is there something wrong? the code i've posted works nicely for me.

2017-03-29 05:33:49 -0500 answered a question getting score and raw data of each circle with CvHoughCircles

I eventually found an answer. if you get into the code (the function is 'enter code hereicv_HoughCircles'), look for the variable 'accum': it is the accumulator of the scores for the various circle centers. to extract, say, the max score just type:

double minVal; // the maximum score
double maxVal;
Mat acc = cvarrToMat(accum); // convert accum to a mat
minMaxLoc(acc, &minVal, &maxVal); // calculate max and min score

hope this helps, Guido.

2017-03-09 07:05:31 -0500 commented answer Possible BUG in denoise_TVL1

Indeed, the problem was with the input argument, I did not understand that a vector<mat> rather than a Mat was needed. Thanks and sorry for the double post.

2017-03-09 05:58:01 -0500 commented answer Possible BUG in denoise_TVL1

I've tried with several images, but of the same type. jpg in grayscale

2017-03-09 05:09:10 -0500 asked a question Possible BUG in denoise_TVL1

I re-ask the question since I didnt found help with that. I'm pretty about to post it in the BUG section, if still nobody has any clue.

I would like to denoise a grayscale image using the TV regularization, in order to prevent sharp edges being smoothed out. I'm working in win10 with Qt 5.4.1, mingw compiler and OpenCV 3.0. I tried the aforementioned algorithm but this gives me the following error: OpenCV Error: Assertion failed ((flags & FIXED_TYPE) != 0) in type, file C:\opencv\sources\modules\core\src\matrix.cpp, line 1821 seems like a type error, but it looks strange to me since I'm just loading a grayscale image. please note that the function 'fastNlMeansDenoising' works flawlessly within the same framework. For better clarity, here's the pseudo code:

String  imageName  = "imageName.jpg";
Mat I = imread(imageName, CV_LOAD_IMAGE_GRAYSCALE);
double lambda = 2;
int niters = 5;
Mat Denoised;
denoise_TVL1( I, Denoised,  lambda,  niters);       //  ! NOT WORKING !
fastNlMeansDenoising(I, Denoised, 8, 7, 25);        //  ! WORKING !

thank you for your help, Guido.

2017-03-06 02:58:29 -0500 commented question denoise_TVL1 not working?

still could not believe no-one is giving any hint. is this question so trivial?

2017-03-06 02:55:02 -0500 commented question How to use my HOG matrix in the SVM classifier?

you've already trained your svm when typing:

// Train the SVM
    svm->train(trainDataMat, ROW_SAMPLE, labels);

you don't need to train it another time

2017-03-03 10:40:35 -0500 commented question How to use my HOG matrix in the SVM classifier?

the .xml file contains the trained SVM data you'll use for prediction (i.e. support vectors, margin, etc...); try to open it with a txt editor to see that. once you have it, just use it for prediction (svm->predict...); it is meaningless to re-train another svm using the .xml as you did.

2017-03-03 09:02:23 -0500 commented question How to use my HOG matrix in the SVM classifier?

something like:

  • load your svm

Ptr<ml::svm> svm = ml::SVM::load<cv::ml::svm>(yourSVMfilename);

  • compute hog features (same parameters you used for training!)

HOGd.compute(yourImage, descriptorsValues);

  • classify with the svm:

previsionLabel = svm->predict(descriptorsValues, noArray(), 0);

is it helpful?

2017-03-03 05:04:25 -0500 commented question How to use my HOG matrix in the SVM classifier?

it seems your code is training then saving your svm classifier. once you have your .xml file you just have to load it and then use svm->predict to classify test images. is this comment revealing or do I misunderstood your question?

2017-03-03 02:33:45 -0500 received badge  Enthusiast
2017-03-02 05:36:48 -0500 commented question denoise_TVL1 not working?

any clue? I think variational denoising (especially using the L1 gradient norm) is quite important in the field of image treatment...

2017-03-01 08:18:12 -0500 commented question denoise_TVL1 not working?

forget to say: my compiler is mingw...

2017-03-01 05:16:28 -0500 asked a question denoise_TVL1 not working?

I would like to denoise a grayscale image using the TV regularization, in order to prevent sharp edges being smoothed out. I'm working in win10 with Qt 5.4.1 and OpenCV 3.0. I tried the aforementioned algorithm but this gives me the following error:

OpenCV Error: Assertion failed ((flags & FIXED_TYPE) != 0) in type, file C:\opencv\sources\modules\core\src\matrix.cpp, line 1821

seems like a type error, but it looks strange to me since I'm just loading a grayscale image. please note that the function 'fastNlMeansDenoising' works flawlessly within the same framework.

For better clarity, here's the pseudo code:

String  imageName  = "imageName.jpg";
Mat I = imread(imageName, CV_LOAD_IMAGE_GRAYSCALE);
double lambda = 2;
int niters = 5;
Mat Denoised;
denoise_TVL1( I, Denoised,  lambda,  niters);       //  ! NOT WORKING !
fastNlMeansDenoising(I, Denoised, 8, 7, 25);        //  ! WORKING !

any hint? thank you, Guido.

2017-01-04 02:36:11 -0500 commented question Quadratic Programming in OpenCV 3.0.0

Thanks Lorena. I looked at the new opencv release doc you suggested but still there's no QP. thanks also for the link to the code, which is very interesting although indeed quite taylored on svm kind of 'Q matrices' and therefore not very useful for me.

2017-01-03 09:57:46 -0500 asked a question Quadratic Programming in OpenCV 3.0.0

I'm recently trying to solve a problem which involves quadratic (semi-definite) programming in C++. since I sometimes use OpenCV library and I'm aware that SVM is indeed supported, I'm rather astonished that in this page: http://docs.opencv.org/3.0-beta/modul... no stuff for solving QP pbs is provided. Am I wrong? How a SVM could be trained without using QP's methods? Many thanks for your kind answers. Guido

2016-10-21 02:47:22 -0500 commented question Stitching two fisheye images

in order to undistort, you would perhaps try hough circles transform to find the outer contour and then use linear-polar to rectify, given the aforementioned circle. (chouette! c'est le palais royal à Paris!)

2016-10-18 05:16:34 -0500 commented question Where to start with pattern recognition

try with generalized hough transform if the shape is reasonably known or match feature beetween images with kaze or similar.

2016-10-18 05:10:31 -0500 commented question getting score and raw data of each circle with CvHoughCircles

i'm interested in the same thing. i've seen someone modified the hough line finder code in order to do that. unfortunately, those 2 routines are a bit different so i wasnt able to copy the modification they did on houghline. i suggest you, if you'd like to jump into the code, to look closer to the variables 'adata' as well as 'accum' in the function 'icvHoughCirclesGradients'

2016-10-11 02:33:02 -0500 commented answer How to initialize a Mat object with zeros

thanks for the editing!

2016-10-11 02:16:45 -0500 answered a question How to initialize a Mat object with zeros

for a grayscale image this should work (works for me, I use openCV 3.0):

 Mat zeroMat = Mat.zeros(n_rows, n_cols, CvType.CV_8UC1);

where n_rows and n_cols are the number of rows and colums (thus, int) respectively. if your image is not grayscale, change the last entry.