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

asked 2013-10-12 21:46:22 -0500

ghalibjanjua gravatar image

updated 2013-10-12 22:01:06 -0500

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 , 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 ));   

  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 ...
(more)
edit retag flag offensive close merge delete