Ask Your Question

thevinci's profile - activity

2020-06-09 03:25:41 -0600 received badge  Popular Question (source)
2016-01-04 22:32:19 -0600 received badge  Nice Question (source)
2016-01-04 22:31:46 -0600 received badge  Teacher (source)
2015-12-08 09:44:59 -0600 commented answer vector<vector<Point> > contours 'Unable to read memory error'

I have a similar problem with the /MD c runtime.

heres my problem on findcontours

Any update on how this can be solved?

2015-11-23 06:22:26 -0600 commented question Access violation writing location

@LorenaGdL - i tried your solution. I still have an error but this time its

First-chance exception at 0x67A60004 (opencv_world300d.dll) in DTPproject.exe: 0xC0000005: Access violation reading location 0x00000008.

@StevenPuttemans - I'm developing a cocos2d-x game for android. heres a link to the cocos2d-x website

2015-11-23 04:05:31 -0600 commented question Access violation writing location

Sorry but on what part of the program should I clone the Mat image? I'm still getting the same error after cloning currentQuery.

2015-11-22 22:52:15 -0600 asked a question Access violation writing location

I want to develop a sketch matching game using OpenCV. What I am trying to do is match an image and user's drawing using the Shape Context matching. I can successfully compile and run my project but when I call the findContour function the program will crash and will produce First-chance exception at 0x5C78DE7A (msvcp120d.dll) in DTPproject.exe: 0xC0000005: Access violation writing location 0x00000010 error.

here is my code

vector<cv::Point> CComputeDistance::simpleContour(const Mat& currentQuery, int n = 300)
    vector<vector<Point> > _contoursQuery;
    vector <Point> contoursQuery;
    findContours(currentQuery, _contoursQuery, RETR_LIST, CHAIN_APPROX_NONE);
    for (size_t border = 0; border<_contoursQuery.size(); border++)
        for (size_t p = 0; p<_contoursQuery[border].size(); p++)

    // In case actual number of points is less than n
    int dummy = 0;
    for (int add = (int)contoursQuery.size() - 1; add<n; add++)
        contoursQuery.push_back(contoursQuery[dummy++]); //adding dummy values

    // Uniformly sampling
    random_shuffle(contoursQuery.begin(), contoursQuery.end());
    vector<Point> cont;
    for (int i = 0; i<n; i++)

    return cont;

void CComputeDistance::computeShapeDistance(Mat image, Mat drawing, float &result)
    Ptr <ShapeContextDistanceExtractor> mySC = createShapeContextDistanceExtractor();

    vector<cv::Point> a = simpleContour(image);
    vector<cv::Point> b = simpleContour(drawing);

    result = mySC->computeDistance(a, b);

void CComputeDistance::loopCompute(Mat image, Mat drawing, float &sum)
    int p = 20;
    for (int i = 0; i < 5; i++)
        float shapeDistance;
        computeShapeDistance(image, drawing, shapeDistance);

        sum = sum + shapeDistance;
        p = p + 20;

what I am really trying to achieve is get the value of "sum" after calling the method loopCompute in which it iterates 5x in loop.

Here is the code that call will the method

CComputeDistance::loopCompute( image, drawing, sum);

Im using visual studio 2013 community and this is what the local variable looks like after the break on debug mode.

image description

The program above runs perfectly if I run it in android but it fails on windows. I think it has something to do with the configuration of Visual Studio to OpenCV.

Any ideas?

EDIT: Here's what the CALL STACK looks like in Visual Studio. VISUAL STUDIO

2015-07-20 06:31:36 -0600 asked a question how to overlay shapes in shape context/hausdorff matching.

Im using both the shape context and hausdorff distance algorithms to extract the distance between two matrices, but I want to visualize the match results. Is there any way I can overlay the matched shape in a form of a Mat?

2015-07-15 02:19:30 -0600 asked a question chamfer matching in opencv 3.0 removed

The chamfer matching algorithm had been removed completely in version 3.0. What are other algorithms that I can use to match hand drawn images vs contour or edge maps. I would like to get the similarity scores of the matched result. And I also want this to run on android. thanks'

2015-07-15 01:27:49 -0600 commented question chamfer matching on android

is there any alternative that i can use? I'm planning to compare a hand drawn image(sketch) vs contour extracted from an image. I would like to get the similarity score.

2015-07-15 00:35:39 -0600 asked a question chamfer matching on android

Anyone here have tried implementing the chamerMatching method on android using opencv4android? I cant get it to work properly on my device galaxy tab 3 kitkat.

the application crashes as soon as I call the chamerMatching method.

here's the screenshot of the logcat from where the problem starts. image description

it seems like a memory problem.

I'm trying to create an application the will compute the similarity scores between two edge maps/matrices using the chamfer matching algorithm provided on the contrib folder of opencv 2.4.11.

heres my code.

public static float getScore(Mat img, Mat tpl)

    if (img.empty() | tpl.empty())
        System.out.println("Could not read image file.");
        return 0;

    Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY);
    Imgproc.cvtColor(tpl, tpl, Imgproc.COLOR_BGR2GRAY);

    Mat cimg = new Mat(img.rows(), img.cols(), CvType.CV_8UC1);
    Imgproc.cvtColor(img, cimg, Imgproc.COLOR_GRAY2BGR);

    List<MatOfPoint> results = new Vector<>();
    MatOfFloat costs = new MatOfFloat();

    int best = Contrib.chamerMatching(img, tpl, results, costs);

    if (best < 0) {
        System.out.println("matching not found");
        return 0;

    System.out.println("Chamfer Distance = " + costs.toList().get(best));

    for (int i =0; i < results.get(best).rows(); i++)
    {, results.get(best).toArray()[i], 0, new Scalar(0,255,0));

    int count_contour = Core.countNonZero(img);

    Imgproc.cvtColor(cimg, cimg, Imgproc.COLOR_BGR2GRAY);
    Imgproc.threshold(cimg, cimg, 150, 255, Imgproc.THRESH_BINARY);
    int count_white = Core.countNonZero(cimg);

    System.out.println("Contour = " + count_contour);
    System.out.println("White = " + count_white);

    float m = count_contour - count_white;
    float d = m / count_contour;
    float s = d * 100;

    return s;

heres the code that will call method getScore.

easyBtn.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v){

                    Mat img = new Mat(257,257, CvType.CV_8UC1);
                    Mat tpl = new Mat(257,257, CvType.CV_8UC1);

                    Bitmap imgBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo_in_clutter);
                    Bitmap tplBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo);

                    Utils.bitmapToMat(imgBitmap, img);
                    Utils.bitmapToMat(tplBitmap, tpl);

                    Log.i("CHAMFER TEST", "Score = " + ChamferTest.getScore(img, tpl));

2015-05-13 08:02:38 -0600 received badge  Scholar (source)
2015-05-13 04:00:00 -0600 received badge  Self-Learner (source)
2015-05-12 10:45:56 -0600 answered a question Chamfer Matching match score

Thanks for your help @Storiy. I was able to get what I wanted. I added these following codes in chamfer.cpp

imshow("result0", cimg);

int count_pixels = countNonZero(img);
imshow("result1", img);

cvtColor(cimg, cimg, CV_BGR2GRAY);
threshold( cimg, cimg, 200, 255, THRESH_BINARY );
int count_white = countNonZero(cimg);

cout << "Contour = " << count_pixels << endl;
cout << "White = " << count_white << endl;

float m = count_contour - count_white;
float d = m / count_contour;
float s = d * 100;

cout << "Similarity = " << s << endl;

imshow("result2", cimg);

image description

Contour = 1572 White = 35 Similarity = 97.7735

2015-05-12 10:39:51 -0600 commented question Chamfer Matching match score

Thanks man it solved my problem.

2015-05-11 08:51:16 -0600 received badge  Enthusiast
2015-05-09 11:00:03 -0600 commented question Chamfer Matching match score

Thanks for your help. I'm total a beginner in opencv I'm a bit confused on the mask operation. Do you have any examples on how to use mask in counting pixels in matching points?

2015-05-05 06:22:52 -0600 received badge  Student (source)
2015-05-05 05:16:26 -0600 received badge  Editor (source)
2015-05-05 01:02:47 -0600 asked a question Chamfer Matching match score

I am currently working on a project that will utilize the chamfer matching algorithm. The program will show an image and then a user will try draw the image using a touch device. The program will then match and compute the similarity scores of the hand drawn image vs the given image based on their edges.

image description image description

I had reviewed the chamfer matching example from the /opencv/samples/cpp. The example provides a way on how to use the chamerMatching() effectively but it does not provide the chamfer distance score between the template image and the image edge map. My question is what is the specific function/method i should use to get the chamfer score of the hand drawn image against the given image. Is there also a way to get the similarity score in percentage?

2015-05-04 21:17:32 -0600 received badge  Supporter (source)