Assertion failed (...) in circle

asked 2015-07-04 12:49:06 -0500

muha.ko gravatar image

updated 2015-07-05 00:39:28 -0500

berak gravatar image

Hello everybody,

I am using opencv 3.0

I got following error message: OpenCV Error: Assertion failed (radius >= 0 && thickness <= 255 && 0 <= shift && shift <= XY_SHIFT) in cv::circle, file C:\builds\master_PackSlave-win32-vc12-shared\opencv\modul es\imgproc\src\drawing.cpp, line 1744

This is the code:

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

using namespace std;
using namespace cv;


int main(int argc, char** argv)
{
    IplImage* img = cvLoadImage("lena.JPG");
    cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
    cvShowImage("Example1", img);

    Mat image = cvarrToMat(img);
    CascadeClassifier face_cascade;
    face_cascade.load("C:/Users/Muha/Documents/visual studio 2015/Projects/Test_Einrichtung_opencv/Test_Einrichtung_opencv/haarcascade_frontalface_alt2.xml");
    String face_cascade_name = "haarcascade_frontalface_alt2.xml";
    if (!face_cascade.load(face_cascade_name)) { printf("--(!)Error loading\n"); return -1; };
    std::vector<Rect> faces;
    face_cascade.detectMultiScale(image, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));

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


    imshow("Detected Face", image);


    waitKey(0);
    return 0;
}

Need your help. Thanks in advance!

edit retag flag offensive close merge delete

Comments

first of all, - please use Mat image = imread("lena.png"); - get rid of all IplImages, cv* functions, and #include <opencv2/opencv.hpp> , not deprecated c-api headers like "opencv/cv.h". those all have to go.

berak gravatar imageberak ( 2015-07-05 00:47:44 -0500 )edit