Ask Your Question
0

EXCEPTION_access_violation using Hough circle transform

asked 2015-04-28 22:38:17 -0500

Pinpin gravatar image

updated 2015-04-29 01:08:36 -0500

berak gravatar image

I'm a newbie using Opencv 3.0 . I keep getting access violation error and i don't know how to fix it. Please help!!!!

// app1.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp" // has cvtColor


#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    Mat src, src_gray;

    /// Read the image
      src = imread("Tennisball2.PNG",1);

    if (!src.data)
    {
        cout << "EMPTY" << endl;
        return -1;
    }

    /// Convert it to gray
    cvtColor(src, src_gray, COLOR_BGR2GRAY);

    /// Reduce the noise so we avoid false circle detection
    GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2);

    vector<Vec3f> face;

    /// Apply the Hough Transform to find the circles
    HoughCircles(src_gray, face, HOUGH_GRADIENT, 1, src_gray.rows / 8, 200, 100, 0, 0);
    //waitKey(1000);

    /// Draw the circles detected
    for (size_t  i = 0;  i < face.size() ; i++)
    {
    Point center(cvRound(face[i][0]), cvRound(face [i][1]));
    int radius = cvRound(face [i][2]);
    // circle center
    circle(src, center, 3, Scalar(0, 255, 0), -1, 8, 0);
    // circle outline
    circle(src, center, radius, Scalar(0, 0, 255), 3, 8, 0);
    }

    /// Show your results
    namedWindow("Hough Circle Transform Demo", WINDOW_AUTOSIZE);
    imshow("Hough Circle Transform Demo", src);

    waitKey(33);
    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-04-29 03:25:38 -0500

Okay, there are some conflicts here. You state you are using OpenCV3.0 ... so start by changing

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"

towards the correct headers (which are a level up) and not the backwards compatibility headers. Also the highgui module was split into seperate modules.

#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/imgproc.hpp"

And now check again if it works. More info can be found in the transition guide.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-04-28 22:38:17 -0500

Seen: 82 times

Last updated: Apr 29 '15