My program run perfectly when I convert data from buffer into Mat (program to run video from external camera with frame grabber card). But after I try to develop a program to detect face, it has triggered a breakpoint.
My output window shows as follow:
/*
HEAP[my.exe]: Invalid address specified to RtlValidateHeap ( 03EC0000, 03F10ED0) // these codes are changing every debug.
This may be due to a corruption of the heap, which indicates a bug in my.exe or any of the DLLs it has loaded.
This may also due to the user pressing F12 while ......
*/
10/1/15
Here, I include the code:
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
#define _NIWIN
#include "niimaq.h"
#include <ctype.h>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int, char**)
{
Mat myocv;
Mat myocv0;
Mat myocv1;
static SESSION_ID Sid = 0;
static BUFLIST_ID Bid = 0;
static INTERFACE_ID Iid = 0;
static Int8 *ImaqBuffer;
char dateiname[20];
size_t m=0;
namedWindow("opencvok", cv:: WINDOW_AUTOSIZE);
//create the cascade classifier object used for the face detection
CascadeClassifier face_cascade;
//use the haarcascade_frontalface_alt.xml library
face_cascade.load("haarcascade_frontalface_alt.xml");
//NI setup
imgInterfaceOpen ("img0", &Iid);
imgSessionOpen (Iid, &Sid);
imgGrabSetup (Sid, TRUE);
while(TRUE)
{
imgGrab(Sid, (void **)&ImaqBuffer, TRUE);
myocv = Mat(Size(1000,1000) , CV_16SC1, ImaqBuffer);
myocv0 = myocv.clone();
myocv0.convertTo(myocv1, CV_8UC1, 1,0);
//create a vector array to store the face found
std::vector<Rect> faces;
//find faces and store them in the vector array
face_cascade.detectMultiScale(myocv1, faces, 1.1, 3, CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_SCALE_IMAGE, Size(30, 30));
//draw a rectangle for all found faces in the vector array on the original image
for (size_t 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(myocv1, center, Size(faces[i].width*0.5, faces[i].height*0.5),0,0,360,Scalar(255,0, 255),4,8,0);
Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
Point pt2(faces[i].x, faces[i].y);
rectangle(myocv1, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);
}
}
imshow("opencvok", myocv1);
waitKey(33);
}
imgClose(Sid, TRUE);
imgClose(Iid, TRUE);
return 0;
}