Ask Your Question

Revision history [back]

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory.

Dear All,

Hi, Need Help.

I am doing work on emotion recognition, using FANN Library in it. It Build fine but during .exe it give following error:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at fann_run(fann* , Single* ) at FaceDetector.detect_emotion(FaceDetector* , DistanceFeatures emotion, Dist anceFeatures neutral, Double* output) in c:\down\uf-lightbot-read-only\src\faced etector.cpp:line 128 at process_features(FaceDetector* face_detect, Mat* frame, Face* face) in c:\ down\uf-lightbot-read-only\src\main.cpp:line 176 at main(Int32 argc, SByte argv) in c:\down\uf-lightbot-read-only\src\main.c pp:line 74 at mainCRTStartup()**

Can any body help me what is the problem ?

main.cpp code is as follows.

include <iostream>

include <cmath>

include "FaceFeatures.h"

include "FaceDetector.h"

include <opencv2 highgui="" highgui.hpp="">

include <cstdlib>

using namespace std; using namespace cv;

void process_features(FaceDetector &face_detect,Mat &frame, Face face);

int main(int argc, char argv[]) { CvCapture capture = NULL;

double t = 0.0; Mat frame, frameCopy;

Mat gray; string fname; vector<face> faces;

unsigned int kmod = 0;

FaceDetector faceDetector("haarcascade_frontalface_alt.xml", "haarcascade_mcs_mouth.xml", "haarcascade_mcs_nose.xml", "haarcascade_mcs_lefteye.xml", "haarcascade_mcs_righteye.xml");

capture = cvCaptureFromCAM(0); cvNamedWindow("result", 1);

if( capture ) { cout << "In capture ..." << endl; for(;;) { kmod++; IplImage* iplImg = cvQueryFrame( capture ); frame = iplImg;

  if( frame.empty() )
    break;

  if( iplImg->origin == IPL_ORIGIN_TL )
    frame.copyTo( frameCopy );
  else 
    flip( frame, frameCopy, 0 );

  if( waitKey( 10 ) >= 0 )
    goto _cleanup_;

if(kmod%2 == 0) {
  faces.clear(); /*Empty face list*/

faceDetector.detect(frameCopy, faces); } vector<face>::const_iterator it; for(it = faces.begin(); it != faces.end(); it++) { process_features(faceDetector, frameCopy, *it); } imshow("result", frameCopy); } }

_cleanup_: cvReleaseCapture( &capture );

return 0; }

double calc_dist(Point p1, Point p2) { double v,aa,bb; aa=p1.x -p2.x; bb=p1.y-p2.y ; v = sqrt(pow(aa,2) + pow (bb,2 )); return v; }

void process_features(FaceDetector &face_detect, Mat &frame, Face face) { static bool initialized = false; static DistanceFeatures neutral; static int init_counter = 0;

// cout<<"processing"<<endl; rectangle(frame,="" point(face.face_box.x,="" face.face_box.y),="" point(face.face_box.x+="" face.face_box.width,="" face.face_box.y+face.face_box.height),="" cv_rgb(0,="" 0="" ,="" 255="" ));="" <="" p="">

circle(frame, face.features.mouth.lip_left_edge, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.mouth.lip_right_edge, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.mouth.lip_top_center, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.mouth.lip_bottom_center, 3, CV_RGB(255, 0 , 0 ), -1);

circle(frame, face.features.eyes.left_eye_top, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.eyes.left_eye_bottom, 3, CV_RGB(255, 0 , 0 ), -1);

circle(frame, face.features.eyes.right_eye_top, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.eyes.right_eye_bottom, 3, CV_RGB(255, 0 , 0 ), -1);

circle(frame, face.features.brows.left_brow_left, 3, CV_RGB(0, 255 , 0 ), -1); circle(frame, face.features.brows.left_brow_center, 3, CV_RGB(0, 255 , 0 ), -1); circle(frame, face.features.brows.left_brow_right, 3, CV_RGB(0, 255 , 0 ), -1);

circle(frame, face.features.brows.right_brow_left, 3, CV_RGB(0, 255 , 0 ), -1); circle(frame, face.features.brows.right_brow_center, 3, CV_RGB(0,255 , 0 ), -1); circle(frame, face.features.brows.right_brow_right, 3, CV_RGB(0, 255 , 0 ), -1);

circle(frame, face.features.nose.center, 3, CV_RGB(0, 255 , 0 ), -1);

double mouth_w = calc_dist(face.features.mouth.lip_left_edge, face.features.mouth.lip_right_edge); double mouth_h = calc_dist(face.features.mouth.lip_top_center, face.features.mouth.lip_bottom_center);

double d_left_eye = calc_dist(face.features.eyes.left_eye_top, face.features.eyes.left_eye_bottom); double d_right_eye = calc_dist(face.features.eyes.right_eye_top, face.features.eyes.right_eye_bottom);

double d_left_brow_left = calc_dist(face.features.brows.left_brow_left, face.features.nose.center); double d_left_brow_middle = calc_dist(face.features.brows.left_brow_center, face.features.nose.center); double d_left_brow_right = calc_dist(face.features.brows.left_brow_right, face.features.nose.center);

double d_right_brow_left = calc_dist(face.features.brows.right_brow_left, face.features.nose.center); double d_right_brow_middle = calc_dist(face.features.brows.right_brow_center, face.features.nose.center); double d_right_brow_right = calc_dist(face.features.brows.right_brow_right, face.features.nose.center);

DistanceFeatures tmp; tmp.mouth_w = mouth_w; tmp.mouth_h = mouth_h; tmp.d_left_eye = d_left_eye; tmp.d_right_eye = d_right_eye;

if 0

tmp.d_left_brow_left = d_left_brow_left; tmp.d_left_brow_middle = d_left_brow_middle; tmp.d_left_brow_right = d_left_brow_right;

tmp.d_right_brow_left = d_right_brow_left; tmp.d_right_brow_middle = d_right_brow_middle; tmp.d_right_brow_right = d_right_brow_right;

endif

if(init_counter == 0) { cout<<"Calibrating neutral face.."<<endl; init_counter++;="" }="" else="" if(init_counter="=" 20)="" {="" initialized="true;" neutral="tmp;" init_counter++;<="" p="">

cout<<"Calibrated!"<<endl;

} else { init_counter++; }

double out[4];

if(initialized) { face_detect.detect_emotion(tmp, neutral, out); for(int i=0;i<4;i++) {cout<<out[i]&lt;&lt;" ";}="" cout&lt;<endl;="" }="" }<="" p="">

facedetector.cpp code is as follows:

include <iostream>

include "HaarCascadeObjectDetector.h"

include "FaceDetector.h"

//#include "fann.h"

include<malloc.h>

include<opencv2\core\core.hpp>

using namespace std; using namespace cv;

//struct fann *ann;

FaceDetector::FaceDetector(string face_cascade_file, string mouth_cascade_file, string nose_cascade_file, string left_eye_cascade_file, string right_eye_cascade_file) {

this->detector = new HaarCascadeObjectDetector(face_cascade_file); this->mouthFeatureDetector = new MouthFeatureDetector(mouth_cascade_file); this->noseFeatureDetector = new NoseFeatureDetector(nose_cascade_file); this->eyeFeatureDetector = new EyeFeatureDetector(left_eye_cascade_file, right_eye_cascade_file); this->browFeatureDetector = new BrowFeatureDetector();

this->ann = fann_create_from_file("emotions.net"); }

FaceDetector::FaceDetector(cv::CascadeClassifier face_cascade, cv::CascadeClassifier mouth_cascade, cv::CascadeClassifier nose_cascade, cv::CascadeClassifier left_cascade, cv::CascadeClassifier right_cascade) { this->detector = new HaarCascadeObjectDetector(face_cascade); this->mouthFeatureDetector = new MouthFeatureDetector(mouth_cascade); this->noseFeatureDetector = new NoseFeatureDetector(nose_cascade); this->eyeFeatureDetector = new EyeFeatureDetector(left_cascade, right_cascade); this->browFeatureDetector = new BrowFeatureDetector();

this->ann = fann_create_from_file("emotions.net"); }

FaceDetector::~FaceDetector() { delete this->detector; delete this->mouthFeatureDetector; delete this->noseFeatureDetector; delete this->eyeFeatureDetector; delete this->browFeatureDetector;

fann_destroy(this->ann); }

int FaceDetector::detect(Mat image, vector<face>& faces) { Mat gray; vector<rect> face_rects; Face tmp;

cvtColor(image, gray, CV_BGR2GRAY); detector->detect(gray, face_rects); /Detect using Haar cascades/

/Do feature detection/ vector<rect>::const_iterator it; for(it = face_rects.begin(); it != face_rects.end(); it++) { tmp.face_box = it; this->mouthFeatureDetector->detect(gray, *it, tmp.features.mouth); /Detect features on mouth/ this->noseFeatureDetector->detect(gray, *it, tmp.features.nose); /Detect features on nose/ this->eyeFeatureDetector->detect(gray, *it, tmp.features.eyes); /Detect eye features/ this->browFeatureDetector->detect(gray, *it, tmp.features.brows); /Detect brow features*/ //cout<<tmp.features.mouth.lip_left_edge&lt;<endl; faces.push_back(tmp);="" }="" return="" null;="" }<="" p="">

if 0

endif

void FaceDetector::detect_emotion(DistanceFeatures emotion, DistanceFeatures neutral,double *output) { fann_type *calc_out;

fann_type input[10]; calc_out=0; /* input[0] = emotion.mouth_w/neutral.mouth_w; input[1] = emotion.mouth_h/neutral.mouth_h;

input[2] = emotion.d_left_eye/neutral.d_left_eye; input[3] = emotion.d_right_eye/neutral.d_right_eye;

input[4] = emotion.d_left_brow_left/neutral.d_left_brow_left; input[5] = emotion. d_left_brow_middle/neutral. d_left_brow_middle; input[6] = emotion.d_left_brow_right/neutral.d_left_brow_right;

input[7] = emotion.d_right_brow_left/neutral.d_right_brow_left; input[8] = emotion.d_right_brow_middle/neutral.d_right_brow_middle; input[9] = emotion.d_right_brow_right/neutral.d_right_brow_right; */ input[0] = 1.0; input[1] = 1.0; input[2] = 1.0; input[3] = 1.0; input[4] = 1.0; input[5] = 1.0; input[6] = 1.0; input[7] = 1.0; input[8] = 1.0; input[9] = 1.0;

calc_out = fann_run(this->ann, input);

//output=((double *) (malloc(25 * sizeof(double))));

output[0] = ((double)calc_out[0]); output[1] = ((double)calc_out[1]); output[2] = ((double)calc_out[2]); output[3] = ((double)calc_out[3]);

// free(output);

}

ifdef __TEST__

int main(int argc, char *argv[]) { return 0; }

endif

Waiting for guidance. . .

Thanks.

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory.

Dear All,

Hi, Need Help.

I am doing work on emotion recognition, using VS2010, OpenCV & FANN Library in it. It Build fine but during .exe it give following error:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at fann_run(fann* fann_run(fann , Single* ) at FaceDetector.detect_emotion(FaceDetector* , DistanceFeatures emotion, Dist anceFeatures neutral, Double* output) in c:\down\uf-lightbot-read-only\src\faced etector.cpp:line 128 at process_features(FaceDetector* face_detect, Mat* frame, Face* face) in c:\ down\uf-lightbot-read-only\src\main.cpp:line 176 at main(Int32 argc, SByte argv) in c:\down\uf-lightbot-read-only\src\main.c pp:line 74 at mainCRTStartup()**mainCRTStartup()*

Can any body help me what is the problem ?

main.cpp

**main.cpp** code is as follows.

include <iostream>

include <cmath>

include "FaceFeatures.h"

include "FaceDetector.h"

include <opencv2 highgui="" highgui.hpp="">

include <cstdlib>

follows. #include <iostream> #include <cmath> #include "FaceFeatures.h" #include "FaceDetector.h" #include <opencv2/highgui/highgui.hpp> #include <cstdlib> using namespace std; using namespace cv;

cv; void process_features(FaceDetector &face_detect,Mat &frame, Face face);

face); int main(int argc, char argv[]) { CvCapture *argv[]) { CvCapture* capture = NULL;

NULL; double t = 0.0; Mat frame, frameCopy;

frameCopy; Mat gray; string fname; vector<face> faces;

vector<Face> faces; unsigned int kmod = 0;

0; FaceDetector faceDetector("haarcascade_frontalface_alt.xml", "haarcascade_mcs_mouth.xml", "haarcascade_mcs_nose.xml", "haarcascade_mcs_lefteye.xml", "haarcascade_mcs_righteye.xml");

"haarcascade_mcs_righteye.xml"); capture = cvCaptureFromCAM(0); cvNamedWindow("result", 1);

1); if( capture ) { cout << "In capture ..." << endl; for(;;) { kmod++; IplImage* iplImg = cvQueryFrame( capture ); frame = iplImg;

iplImg;

      if( frame.empty() )
     break;

   if( iplImg->origin == IPL_ORIGIN_TL )
     frame.copyTo( frameCopy );
   else 
     flip( frame, frameCopy, 0 );

   if( waitKey( 10 ) >= 0 )
     goto _cleanup_;

 if(kmod%2 == 0) {
   faces.clear(); /*Empty face list*/

faceDetector.detect(frameCopy, faces); } vector<face>::const_iterator vector<Face>::const_iterator it; for(it = faces.begin(); it != faces.end(); it++) { process_features(faceDetector, frameCopy, *it); } imshow("result", frameCopy); } }

} _cleanup_: cvReleaseCapture( &capture );

); return 0; }

} double calc_dist(Point p1, Point p2) { double v,aa,bb; aa=p1.x -p2.x; bb=p1.y-p2.y ; v = sqrt(pow(aa,2) + pow (bb,2 )); return v; }

} void process_features(FaceDetector &face_detect, Mat &frame, Face face) { static bool initialized = false; static DistanceFeatures neutral; static int init_counter = 0;

0; // cout<<"processing"<<endl; rectangle(frame,="" point(face.face_box.x,="" face.face_box.y),="" point(face.face_box.x+="" face.face_box.width,="" face.face_box.y+face.face_box.height),="" cv_rgb(0,="" 0="" ,="" 255="" ));="" <="" p="">

cout<<"processing"<<endl; rectangle(frame, Point(face.face_box.x, face.face_box.y), Point(face.face_box.x+ face.face_box.width, face.face_box.y+face.face_box.height), CV_RGB(0, 0 , 255 )); circle(frame, face.features.mouth.lip_left_edge, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.mouth.lip_right_edge, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.mouth.lip_top_center, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.mouth.lip_bottom_center, 3, CV_RGB(255, 0 , 0 ), -1);

-1); circle(frame, face.features.eyes.left_eye_top, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.eyes.left_eye_bottom, 3, CV_RGB(255, 0 , 0 ), -1);

-1); circle(frame, face.features.eyes.right_eye_top, 3, CV_RGB(255, 0 , 0 ), -1); circle(frame, face.features.eyes.right_eye_bottom, 3, CV_RGB(255, 0 , 0 ), -1);

-1); circle(frame, face.features.brows.left_brow_left, 3, CV_RGB(0, 255 , 0 ), -1); circle(frame, face.features.brows.left_brow_center, 3, CV_RGB(0, 255 , 0 ), -1); circle(frame, face.features.brows.left_brow_right, 3, CV_RGB(0, 255 , 0 ), -1);

-1); circle(frame, face.features.brows.right_brow_left, 3, CV_RGB(0, 255 , 0 ), -1); circle(frame, face.features.brows.right_brow_center, 3, CV_RGB(0,255 , 0 ), -1); circle(frame, face.features.brows.right_brow_right, 3, CV_RGB(0, 255 , 0 ), -1);

-1); circle(frame, face.features.nose.center, 3, CV_RGB(0, 255 , 0 ), -1);

-1); double mouth_w = calc_dist(face.features.mouth.lip_left_edge, face.features.mouth.lip_right_edge); double mouth_h = calc_dist(face.features.mouth.lip_top_center, face.features.mouth.lip_bottom_center);

face.features.mouth.lip_bottom_center); double d_left_eye = calc_dist(face.features.eyes.left_eye_top, face.features.eyes.left_eye_bottom); double d_right_eye = calc_dist(face.features.eyes.right_eye_top, face.features.eyes.right_eye_bottom);

face.features.eyes.right_eye_bottom); double d_left_brow_left = calc_dist(face.features.brows.left_brow_left, face.features.nose.center); double d_left_brow_middle = calc_dist(face.features.brows.left_brow_center, face.features.nose.center); double d_left_brow_right = calc_dist(face.features.brows.left_brow_right, face.features.nose.center);

face.features.nose.center); double d_right_brow_left = calc_dist(face.features.brows.right_brow_left, face.features.nose.center); double d_right_brow_middle = calc_dist(face.features.brows.right_brow_center, face.features.nose.center); double d_right_brow_right = calc_dist(face.features.brows.right_brow_right, face.features.nose.center);

face.features.nose.center); DistanceFeatures tmp; tmp.mouth_w = mouth_w; tmp.mouth_h = mouth_h; tmp.d_left_eye = d_left_eye; tmp.d_right_eye = d_right_eye;

if 0

d_right_eye; #if 0 tmp.d_left_brow_left = d_left_brow_left; tmp.d_left_brow_middle = d_left_brow_middle; tmp.d_left_brow_right = d_left_brow_right;

d_left_brow_right; tmp.d_right_brow_left = d_right_brow_left; tmp.d_right_brow_middle = d_right_brow_middle; tmp.d_right_brow_right = d_right_brow_right;

endif

d_right_brow_right; #endif if(init_counter == 0) { cout<<"Calibrating neutral face.."<<endl; init_counter++;="" }="" else="" if(init_counter="=" 20)="" {="" initialized="true;" neutral="tmp;" init_counter++;<="" p="">

face.."<<endl;
    init_counter++;
  }
  else if(init_counter == 20) {
    initialized = true;
    neutral = tmp;
    init_counter++;

    cout<<"Calibrated!"<<endl;

} else { init_counter++; }

} double out[4];

out[4]; if(initialized) { face_detect.detect_emotion(tmp, neutral, out); for(int i=0;i<4;i++) {cout<<out[i]&lt;&lt;" ";}="" cout&lt;<endl;="" }="" }<="" p="">

facedetector.cpp {cout<<out[i]<<" ";} cout<<endl; } } **facedetector.cpp** code is as follows:

include <iostream>

include "HaarCascadeObjectDetector.h"

include "FaceDetector.h"

follows: #include <iostream> #include "HaarCascadeObjectDetector.h" #include "FaceDetector.h" //#include "fann.h"

include<malloc.h>

include<opencv2\core\core.hpp>

"fann.h" #include<malloc.h> #include<opencv2\core\core.hpp> using namespace std; using namespace cv;

cv; //struct fann *ann;

*ann; FaceDetector::FaceDetector(string face_cascade_file, string mouth_cascade_file, string nose_cascade_file, string left_eye_cascade_file, string right_eye_cascade_file) {

{ this->detector = new HaarCascadeObjectDetector(face_cascade_file); this->mouthFeatureDetector = new MouthFeatureDetector(mouth_cascade_file); this->noseFeatureDetector = new NoseFeatureDetector(nose_cascade_file); this->eyeFeatureDetector = new EyeFeatureDetector(left_eye_cascade_file, right_eye_cascade_file); this->browFeatureDetector = new BrowFeatureDetector();

BrowFeatureDetector(); this->ann = fann_create_from_file("emotions.net"); }

} FaceDetector::FaceDetector(cv::CascadeClassifier face_cascade, cv::CascadeClassifier mouth_cascade, cv::CascadeClassifier nose_cascade, cv::CascadeClassifier left_cascade, cv::CascadeClassifier right_cascade) { this->detector = new HaarCascadeObjectDetector(face_cascade); this->mouthFeatureDetector = new MouthFeatureDetector(mouth_cascade); this->noseFeatureDetector = new NoseFeatureDetector(nose_cascade); this->eyeFeatureDetector = new EyeFeatureDetector(left_cascade, right_cascade); this->browFeatureDetector = new BrowFeatureDetector();

BrowFeatureDetector(); this->ann = fann_create_from_file("emotions.net"); }

} FaceDetector::~FaceDetector() { delete this->detector; delete this->mouthFeatureDetector; delete this->noseFeatureDetector; delete this->eyeFeatureDetector; delete this->browFeatureDetector;

this->browFeatureDetector; fann_destroy(this->ann); }

} int FaceDetector::detect(Mat image, vector<face>& vector<Face>& faces) { Mat gray; vector<rect> vector<Rect> face_rects; Face tmp;

tmp; cvtColor(image, gray, CV_BGR2GRAY); detector->detect(gray, face_rects); /Detect /*Detect using Haar cascades/

/Do cascades*/ /*Do feature detection/ vector<rect>::const_iterator detection*/ vector<Rect>::const_iterator it; for(it = face_rects.begin(); it != face_rects.end(); it++) { tmp.face_box = it; *it; this->mouthFeatureDetector->detect(gray, *it, tmp.features.mouth); /Detect /*Detect features on mouth/ mouth*/ this->noseFeatureDetector->detect(gray, *it, tmp.features.nose); /Detect /*Detect features on nose/ nose*/ this->eyeFeatureDetector->detect(gray, *it, tmp.features.eyes); /Detect /*Detect eye features/ features*/ this->browFeatureDetector->detect(gray, *it, tmp.features.brows); /Detect /*Detect brow features*/ //cout<<tmp.features.mouth.lip_left_edge&lt;<endl; faces.push_back(tmp);="" }="" return="" null;="" }<="" p="">

if 0

endif

//cout<<tmp.features.mouth.lip_left_edge<<endl; faces.push_back(tmp); } return NULL; } #if 0 #endif void FaceDetector::detect_emotion(DistanceFeatures emotion, DistanceFeatures neutral,double *output) { fann_type *calc_out;

*calc_out; fann_type input[10]; calc_out=0; /* input[0] = emotion.mouth_w/neutral.mouth_w; input[1] = emotion.mouth_h/neutral.mouth_h;

emotion.mouth_h/neutral.mouth_h; input[2] = emotion.d_left_eye/neutral.d_left_eye; input[3] = emotion.d_right_eye/neutral.d_right_eye;

emotion.d_right_eye/neutral.d_right_eye; input[4] = emotion.d_left_brow_left/neutral.d_left_brow_left; input[5] = emotion. d_left_brow_middle/neutral. d_left_brow_middle; input[6] = emotion.d_left_brow_right/neutral.d_left_brow_right;

emotion.d_left_brow_right/neutral.d_left_brow_right; input[7] = emotion.d_right_brow_left/neutral.d_right_brow_left; input[8] = emotion.d_right_brow_middle/neutral.d_right_brow_middle; input[9] = emotion.d_right_brow_right/neutral.d_right_brow_right; */ input[0] = 1.0; input[1] = 1.0; input[2] = 1.0; input[3] = 1.0; input[4] = 1.0; input[5] = 1.0; input[6] = 1.0; input[7] = 1.0; input[8] = 1.0; input[9] = 1.0;

1.0; calc_out = fann_run(this->ann, input);

input); //output=((double *) (malloc(25 * sizeof(double))));

sizeof(double)))); output[0] = ((double)calc_out[0]); output[1] = ((double)calc_out[1]); output[2] = ((double)calc_out[2]); output[3] = ((double)calc_out[3]);

((double)calc_out[3]); // free(output);

}

ifdef __TEST__

free(output); } #ifdef __TEST__ int main(int argc, char *argv[]) { return 0; }

endif

} #endif

Waiting for guidance. . .

Thanks.