Ask Your Question
0

Hi.. i'm new to opencv and trying shape detection. I have faced the following error "Unhandled exception (opencv_imgproc243d.dll) in ShapeDetection.exe " Can anyone knows how to solve this???

asked 2016-11-16 18:29:41 -0600

updated 2016-11-17 00:42:04 -0600

berak gravatar image

My program,

int main()
{
    //cv::Mat src = cv::imread("polygon.png");
    cv::Mat src;
    cv::Mat gray;
    cv::Mat bw;
    cv::Mat dst;

    std::vector<cv::Point> approx;
    std::vector<std::vector<cv::Point>> contours;

    VideoCapture capture(0);
    int q;

    while (cvWaitKey(30) != 'q')
    {
        capture >> src;
        if (true)
        {
            // Convert to grayscale
            cv::cvtColor(src, gray, CV_BGR2GRAY);

            // Use Canny instead of threshold to catch squares with gradient shading
            blur(gray, bw, Size(3, 3));
            cv::Canny(gray, bw, 80, 240, 3);
            cv::imshow("bw", bw);
            //cv::bitwise_not(bw, bw);

            // Find contours
            cv::findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

            src.copyTo(dst);

            for (int i = 0; i < contours.size(); i++)
            {
                // Approximate contour with accuracy proportional
                // to the contour perimeter
                cv::approxPolyDP(cv::Mat(contours[i]), approx, cv::arcLength(cv::Mat(contours[i]), true)*0.02, true);

                // Skip small or non-convex objects
                if (std::fabs(cv::contourArea(contours[i])) < 100 || !cv::isContourConvex(approx))
                    continue;
..................

Facing the problem in the for loop when i=1 and breaks at point cv::approxPolyDP().

edit retag flag offensive close merge delete

Comments

any chance, you're using debug dlls with release build ?

berak gravatar imageberak ( 2016-11-17 00:51:50 -0600 )edit

Just saying, OpenCV 2.4.3 is already too old by now. Either upgrade to 2.4.13, or directly move to 3.x branch (3.1?)

LorenaGdL gravatar imageLorenaGdL ( 2016-11-17 00:54:25 -0600 )edit

can we see the rest of the while loop ?

berak gravatar imageberak ( 2016-11-17 01:14:21 -0600 )edit

Rest of the while loop...

if (approx.size() == 3) { setLabel(dst, "TRI", contours[i]); // Triangles } else if (approx.size() >= 4 && approx.size() <= 6) { // Number of vertices of polygonal curve int vtc = approx.size();

                    // Get the cosines of all corners
                    std::vector<double> cos;
                    for (int j = 2; j < vtc + 1; j++)
                        cos.push_back(angle(approx[j%vtc], approx[j - 2], approx[j - 1]));

                    // Sort ascending the cosine values
                    std::sort(cos.begin(), cos.end());

                    // Get the lowest and the highest cosine
                    double mincos = cos.front();
                    double maxcos = cos.back();

                    // Use the degrees obtained above and the number of vertices
                    // to determine the shape of the contour
                    if (vtc == 4)
                        setLabel
shoebtamboli gravatar imageshoebtamboli ( 2016-11-17 16:19:05 -0600 )edit

// to determine the shape of the contour if (vtc == 4) setLabel(dst, "RECT", contours[i]); else if (vtc == 5) setLabel(dst, "PENTA", contours[i]); else if (vtc == 6) setLabel(dst, "HEXA", contours[i]); } else { // Detect and label circles double area = cv::contourArea(contours[i]); cv::Rect r = cv::boundingRect(contours[i]); int radius = r.width / 2;

                    if (std::abs(1 - ((double)r.width / r.height)) <= 0.2 &&
                        std::abs(1 - (area / (CV_PI * (radius*radius)))) <= 0.2)
                        setLabel(dst, "CIR", contours[i]);
                }
            }
        cv::imshow("src", src);
        cv::imshow("dst", dst);

    }
shoebtamboli gravatar imageshoebtamboli ( 2016-11-17 16:19:26 -0600 )edit

Also i'll upgrade opencv and test it.... thanks for the reply

shoebtamboli gravatar imageshoebtamboli ( 2016-11-17 16:21:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-17 01:43:10 -0600

KirtiSwagat gravatar image

May be the named dll is missing. Try to find the dll and put it in the folder where your programe is present.

edit flag offensive delete link more

Comments

naw, prog would not run, if a dll is missing.

(nice, that you try to help, though ;)

berak gravatar imageberak ( 2016-11-17 01:49:45 -0600 )edit

dll is present..but still facing the problem..

shoebtamboli gravatar imageshoebtamboli ( 2016-11-17 16:19:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-16 18:29:41 -0600

Seen: 672 times

Last updated: Nov 17 '16