Ask Your Question

Tobyy's profile - activity

2016-12-10 22:47:26 -0600 received badge  Student (source)
2016-12-10 14:25:03 -0600 commented question Problem with Cascade Classifier

Thank you very much! I've now taken samples from a video and optimized minNeighbours and min Size. It works very well.

2016-12-09 07:04:39 -0600 commented question Problem with Cascade Classifier

face_cascade.detectMultiScale(frame_gray, faces, 1.1, 0, 0, cv::Size(10, 10));

2016-12-08 08:23:37 -0600 asked a question Problem with Cascade Classifier

I've problems with the Cascade Classifer. I created 5000 positive samples like this: image description

with this command:

C:\OpenCV31\opencv\build\x64\vc14\bin\opencv_createsamples.exe -img C:\CreateSamples\test\image6.jpg -vec gew.vec -bg neg.txt -num 5000 -w 80 -h 80 -show -maxyangle 0.0 -maxzangle 0.0 -maxxangle 0.5 -bgcolor 0

then i trained a classifier like this:

C:\OpenCV31\opencv\build\x64\vc14\bin\opencv_traincascade.exe -data NEWclassifier -vec gew.vec -bg neg.txt -numStages 15 -numPos 2500 -numNeg 1500 -w 80 -h 80 -precalcValBufSize 4048 -precalcIdxBufSize 4048 -featureType LBP

and get this result:

image description

The Problem is: it detects nearly everything as an object:

I used this image: image description

and get this:

image description

I'm new with Cascade Classifier and read a lot of tutorials and samples, but i don't get my mistake. Can you help me?

I call detectMultiscale like this: face_cascade.detectMultiScale(frame_gray, faces, 1.1, 0, 0, cv::Size(10, 10));

2016-11-24 07:05:11 -0600 commented question Cascade classifier doesn't detect object

Okay, whren i use images wich are lager than than 100x100px it dectects an object everywhere in the image not just in the position of the object. I dont understand why.

2016-11-24 06:20:30 -0600 asked a question Cascade classifier doesn't detect object

Hello everyone, i've trained a Cascade classifier with opencv_traincascade.exe. In the 0-Stage it says HR 1 FA 0. But whren i use it to detect an object it doesn't detect it. I use C++ and OpenCV 3.1. The image size is 100x100px. Even if i use one of the positive images that i used for training it doesnt detect any object. Do you have any ideas what my problem could be?

#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;

// Function Headers
void detectAndDisplay(Mat frame);

// Global variables
// Copy this file from opencv/data/haarscascades to target folder
string face_cascade_name = "C:\\CreateSamples\\classifier\\cascade.xml";
CascadeClassifier face_cascade;
string window_name = "Capture - Face detection";
int filenumber; // Number of file to be saved
string filename;

// Function main
int main(void)
    // Load the cascade
    if (!face_cascade.load(face_cascade_name)) {
        printf("--(!)Error loading\n");
        return (-1);

    // Read the image file
    Mat frame = imread("C:\\CreateSamples\\rawdata\\img02.bmp");

    // Apply the classifier to the frame
    if (!frame.empty()) {
    else {
        printf(" --(!) No captured frame -- Break!");

    int c = waitKey(10000000000);

    if (27 == char(c)) {

    return 0;

// Function detectAndDisplay
void detectAndDisplay(Mat frame)
    std::vector<Rect> faces;
    Mat frame_gray;
    Mat crop;
    Mat res;
    Mat gray;
    string text;
    stringstream sstm;

    cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);

    // Detect faces
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 1.1, 0 | CASCADE_SCALE_IMAGE, Size(1, 1));

    // Set Region of Interest
    cv::Rect roi_b;
    cv::Rect roi_c;

    size_t ic = 0; // ic is index of current element
    int ac = 0; // ac is area of current element

    size_t ib = 0; // ib is index of biggest element
    int ab = 0; // ab is area of biggest element

    for (ic = 0; ic < faces.size(); ic++) // Iterate through all current elements (detected faces)

        roi_c.x = faces[ic].x;
        roi_c.y = faces[ic].y;
        roi_c.width = (faces[ic].width);
        roi_c.height = (faces[ic].height);

        ac = roi_c.width * roi_c.height; // Get the area of current element (detected face)

        roi_b.x = faces[ib].x;
        roi_b.y = faces[ib].y;
        roi_b.width = (faces[ib].width);
        roi_b.height = (faces[ib].height);

        ab = roi_b.width * roi_b.height; // Get the area of biggest element, at beginning it is same as "current" element

        if (ac > ab)
            ib = ic;
            roi_b.x = faces[ib].x;
            roi_b.y = faces[ib].y;
            roi_b.width = (faces[ib].width);
            roi_b.height = (faces[ib].height);

        crop = frame(roi_b);
        resize(crop, res, Size(128, 128), 0, 0, INTER_LINEAR); // This will be needed later while saving images
        cvtColor(crop, gray, CV_BGR2GRAY); // Convert cropped image to Grayscale

                                           // Form a filename
        filename = "";
        stringstream ssfn;
        ssfn << filenumber << ".png";
        filename = ssfn.str();
        filename = "C:\\CreateSamples\\rawdata\\img02detec.bmp";
        imwrite(filename, gray);

        Point pt1(faces[ic].x, faces[ic].y); // Display detected faces on main window - live stream from camera
        Point pt2((faces[ic].x + faces[ic].height), (faces[ic].y + faces[ic].width));
        rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0);

    // Show image
    sstm ...
2016-11-24 06:14:32 -0600 received badge  Enthusiast
2016-11-23 05:46:26 -0600 commented question opencv_traincascade: Calculating numstages numpos numneg

I don't find my problem. I've now selected some more positives (36). But the training stops after the first stage. Even if i just do it with -numStages 2 -numPos 1 -numNeg 10. But why? After the calculation like in the link you posted, there must be enough images.

2016-11-21 10:15:55 -0600 received badge  Editor (source)
2016-11-19 11:31:24 -0600 asked a question opencv_traincascade: Calculating numstages numpos numneg

Hello Everyone, I'm new in to OpenCv and Cascade training. How can I calculate -numstages -numpos -numneg. My .vec file contains 6 positive Samples. And i have 129 negative Images. Can you help me with the calculation?