Ask Your Question

mask2007's profile - activity

2016-05-19 15:09:42 -0500 received badge  Necromancer (source)
2016-05-18 14:52:25 -0500 answered a question opencv CRF(conditional random fields)
2016-04-05 14:58:11 -0500 commented question Simple OpenCV program crashes

@wagp11 Same problem here. Have you figure it out by now? If so could you please share your solution here? Thanks

2016-04-05 14:32:19 -0500 commented question Tutorial code crashes when using QtCreator

@FooBar I Have the same problem. I know that when I comment namedWindow, imshow and waitKey it runs without any error or crash. The problem is the last three line. But the program crashed before running the mian() function and I am still trying to figuring out why. IF you've already found out I would be thankful if you please let me know.

2016-03-09 13:53:01 -0500 commented question Random forest - RTrees - getSplits - type mismatch

@berak it's Windows 10 and OpenCV 3.1. I'll put the whole code up there.

2016-03-09 12:30:57 -0500 commented question Random Forest - confidence and class probability

Thanks @Tetragramm! The machine learning structure in opencv 3 was changed dramatically and it's very different from opencv 2.4. It's not obvious to me how I can access the local variable votes in tree.cpp file.

2016-03-04 08:33:10 -0500 received badge  Enthusiast
2016-03-03 12:06:31 -0500 asked a question Random forest - RTrees - getSplits - type mismatch

Hello,

I'm trying to access RTrees's nodes and trees. Having the following code: ``` #include <iostream>

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\ml\ml.hpp>

using namespace std;
using namespace cv;
using namespace cv::ml;

static Ptr<TrainData> prepareTrainData(Mat& pts, Mat& classes)
{
    Mat samples;
    Mat(pts).reshape(1, (int)pts.rows).convertTo(samples, CV_32F);
    Ptr<TrainData> a = TrainData::create(samples, ROW_SAMPLE, classes);
    return a;
}

int main()
{
    Mat training = (Mat_<float>(7, 2) << 1, 1, 2, 2, 3, 3, 1, 2, 3, 4, 5, 4, 3, 2);
    Mat classes = (Mat_<int>(7, 1) << 0, 0, 0, 1, 1, 2, 2);

    cout << "training data" << endl;
    cout << endl << training << " " << endl << endl;
    cout << "classes" << endl;
    cout << endl << classes << " " << endl << endl;

    Ptr<RTrees> rtrees = RTrees::create();

    rtrees->setMaxDepth(14);
    rtrees->setMinSampleCount(2);
    rtrees->setRegressionAccuracy(0.f);
    rtrees->setUseSurrogates(false);
    rtrees->setMaxCategories(3);
    rtrees->setPriors(Mat());
    rtrees->setCalculateVarImportance(false);

    rtrees->setActiveVarCount(1);
    rtrees->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 5, 0));
    Ptr<TrainData> a = prepareTrainData(training, classes);
    rtrees->train(a);

    // my own prediction
    vector<int> roots = rtrees->getRoots();             // runtime error
    vector<DTrees::Node> nodes = rtrees->getNodes();    // runtime error
    vector<DTrees::Split> splits = rtrees->getSplits();  // runtime error

    Range range = Range(0, (int)roots.size());
    Mat sample = training.row(0);

    int nclasses = 2;
    vector<int> votes(nclasses, 0);
    Mat varIdx0 = a->getVarIdx();
    vector<int> varIdx;
    varIdx0.copyTo(varIdx);                                                        // wrong copy

    getchar();
    return 0;
}

```

I keep getting the memory access violation. Note that rt->getSplits() works by itself and I guess the problem is with the data type of splits.

Also, when I read training data information and want to copy it into a variable:

std::vector<int> catMap;
 data->getCapMap().copyTo(catMap);

it copies garbage into the carMap and I have to copy it element by element instead of using copyTo method. Do you have any idea about these two questions?

Thanks,

2016-03-02 16:06:38 -0500 received badge  Supporter (source)
2016-03-01 16:22:39 -0500 asked a question OpenCV 3.1 Random Forest - rtrees

I'm trying to have access to number of classes and number of votes for each class in an RTrees object in OpenCV 3.1.

Apparently the structure of ver. 3.1 is very different from the previous versions. I'm not sure how to access variables like nclasses, and trees in ver. 3.1.

Does anyone has any insight?

Thanks

2016-02-04 13:04:18 -0500 received badge  Editor (source)
2016-02-04 13:03:53 -0500 asked a question Random Forest - confidence and class probability

This issue has been asked several times on Stack Overflow as well as here. Just wanted to re-check again if some one has any solution for it.

Do you guys know how to get probabilistic prediction from a 2-class random forest in opencv 3.00 (RTrees)?

I know there was predict_prob() method in Opencv 2.4 but it's been disappeared in version 3.00.

No idea why it has been removed in version 3.00 and 3.10!

Thanks,

2016-02-04 09:08:28 -0500 commented question Random Forest confidency.

Hi, have you found a solution for your problem?

2016-02-04 09:02:18 -0500 commented question Random Forest predict_prob in OpenCV 3.0

Hi @prox, have you found a solution for your problem? If so, I would be thankful if you please share it with us. Thanks

2015-09-14 00:17:17 -0500 asked a question Unhandled exception in Contour.exe

Hello,

My code in OpenCV works well up until when I want to find contours:

findContours(src, contours,hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);

then I keep getting the following error:

"Unhandled exception at 0x773e3e28 in Contour.exe: Microsoft C++ exception: cv::Exception at memory location 0x002ff3ac.."

Do you have any idea about this error?

My full code is below.

Thanks

Mat src=Mat(100,200,CV_64F),newimg;
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;

for (int i=25;i<80;i++)
    for(int j=25;j<80;j++)
        src.at<double>(i,j)=1;
imshow("img",src);
waitKey(0);

findContours(src, contours,hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);