Ask Your Question
0

Assertion failed (axes.width >= 0 && axes.height...)line 1772

asked 2015-07-06 14:02:15 -0600

muha.ko gravatar image

updated 2015-07-06 14:42:50 -0600

Eduardo gravatar image

Hello everybody,

In following code I read in my webcam and want to detect face. Unfortunately it does not work. I commented some parts of the end out and I have NO problems only reading in the cam. But the whole code gives the error like below.

Here is the code:

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

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

using namespace std;
using namespace cv;

Mat detectFace(Mat src);

int main()
{
    VideoCapture cap(0);
    namedWindow("window1", 1);

    while (1)
    {
        Mat frame;
        cap >> frame;
        frame = detectFace(frame);

        imshow("window1", frame);
        // Press 'c' to escape
        if (waitKey(1) == 'c') break;
    }

    waitKey(0);
    return 0;
}

Mat detectFace(Mat image)
{
    // Load Face cascade (.xml file)
    CascadeClassifier face_cascade("haarcascade_frontalface_alt2.xml");

    // Detect faces
    std::vector<Rect> faces;
    face_cascade.detectMultiScale(image, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));

    ////// Draw circles on the detected faces
    for (int i = 0; i < faces.size(); i++)
    {
        Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
        ellipse(image, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
    }
    return image;
}

This is the error message:

 OpenCV Error: Assertion failed (axes.width >= 0 && axes.height >= 0 && thickness <= 255 && 0 <= shift && shift <= XY_SHIFT) in cv::ellipse, file C:\builds\master_PackSlave-win32
-vc12-shared\opencv\modules\imgproc\src\drawing.cpp, line 1772

I am looking forward for your support and help. Thank you!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2015-07-06 14:47:50 -0600

with a bit modification as below i compiled and run without problem. ( opencv 2.4.10 , code-block)

"haarcascade_frontalface_alt2.xml" must be at the same directory

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

Mat detectFace(Mat src);

int main()
{
    VideoCapture cap(0);
    namedWindow("window1", 1);

    CascadeClassifier face_cascade("haarcascade_frontalface_alt2.xml");
    std::vector<Rect> faces;

    while (1)
    {
        Mat frame;
        cap >> frame;

        // Detect faces
        face_cascade.detectMultiScale(frame, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));

        // Draw circles on the detected faces
        for (int i = 0; i < faces.size(); i++)
        {
            Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
            ellipse(frame, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
        }

        imshow("window1", frame);
        // Press 'c' to escape
        if (waitKey(1) == 'c') break;
    }

    return 0;
}
edit flag offensive delete link more

Comments

maybe you are using an old version of opencv. if so I would recommend to upgrade

sturkmen gravatar imagesturkmen ( 2015-07-06 15:08:44 -0600 )edit

i am using opencv 3.0 and haarcascade_frontalface_alt2.xml is in the same directory You maybe made a special configuration in Visiual Studio?

muha.ko gravatar imagemuha.ko ( 2015-07-06 16:29:36 -0600 )edit
1

i tried with opencv3. the code runs good.

`Size(faces[i].width*0.5, faces[i].height*0.5)` must causes error according to your configuration in Visual Studio.

i wonder what happens with

    Point center(faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2);
    ellipse(frame, center, Size(faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
sturkmen gravatar imagesturkmen ( 2015-07-06 18:58:25 -0600 )edit

@sturmen thank you very much for your support! Can you please give me some advice how I have to do the configuration in Visiual Studio?

muha.ko gravatar imagemuha.ko ( 2015-07-07 03:25:57 -0600 )edit

did you try the code below?

Point center(faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2);
ellipse(frame, center, Size(faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
sturkmen gravatar imagesturkmen ( 2015-07-07 17:54:59 -0600 )edit

its working now :) even the first version above which I posted here. The error was because of the wrong config in Visiual Studio. @sturkmen thank you very much either!!! (@sturkmen ben size sonra projem hakkinda bi email atmak istiyorum, sizin icin uygun mudur? tekrardan yardiminiz icin cok tesekkür ederim!)

muha.ko gravatar imagemuha.ko ( 2015-07-08 14:07:08 -0600 )edit

what did you do to correct the issue? which configuration in visual studio did you change?

ankurgupta7 gravatar imageankurgupta7 ( 2015-09-09 02:01:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-06 14:02:15 -0600

Seen: 3,179 times

Last updated: Jul 06 '15