samedi 27 janvier 2018

OpenCV Windows Object Detection Error

I am a newbie to OPenCV and I have a problem in my code.

Details: I am trying to use kinect to identify objects. I have trained the OpenCV haarcascade with the following images. Positive Images Size: 192*108 Negative Images Size: 1920*1080 Positive Images Vec: 48*27

The kinect gives a 1920*1080 buffer that I use to create a Mat object to identify an object(waterbottle).

Code:

#pragma once
#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <Kinect.h>
#include <iostream>  
#include <stdio.h>
#include "KinectInit.h"
using namespace std;
using namespace cv;

class detect {
private:
String cascade_name;
CascadeClassifier cascade;
String window_name = "Capture-detection";

public:
detect() {
    cascade_name = "D:/nus/UROP/TrainingData/CascadeTrain/cascade.xml";
    if (!cascade.load(cascade_name)) { 
        printf("--(!)Error loading cascade\n");
        return;
    };
}
detect(String cascade_name) {
    this->cascade_name = cascade_name;
    if (!cascade.load(cascade_name)) { 
        printf("--(!)Error loading cascade\n"); 
        return; 
    };
}
void recog(UINT32 *Frame_ext)
{
    Mat frame=Mat(CIMG_W, CIMG_H, CV_8UC4, Frame_ext);
    //-- 1. Load the cascades
    if (frame.empty()) {
        return ;
    }
    detectAndDisplay(frame);
}
void detectAndDisplay(Mat frame)
{
    std::vector<Rect> detect;
    //Mat frame_gray;
    //cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
    //equalizeHist(frame_gray, frame_gray);
    //-- Detect faces

        cascade.detectMultiScale(frame, detect, 1.4, 5, 0 , Size(50, 30));
        /*
        for (size_t i = 0; i < detect.size(); i++)
        {
            Point center(detect[i].x + detect[i].width / 2, detect[i].y + 
detect[i].height / 2);
            ellipse(frame, center, Size(detect[i].width / 2, 
detect[i].height / 2), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);

        }
        */
        imshow(window_name, frame);

}

};

Problem: There is an exception when I call multiScaleDetect. I am not sure what it exactly means. Exact Error: Exception thrown at 0x00007FFFF82EFFB2 (opencv_world331d.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x000001FD0A79F000.

Upon debugging, I see that the exception occurs somewhere after the size. I am not sure why?

Aucun commentaire:

Enregistrer un commentaire