EXCEPTION_ACCESS_VIOLATION(0xc0000005)在处理语言中使用OpenCV时

时间:2013-01-05 19:40:53

标签: java opencv processing

我的处理代码如下。

import hypermedia.video.*;
import processing.video.*;
import java.awt.Rectangle;

OpenCV opencv;

int width = 320;
int height = 240;

void setup() {

size( 320, 240 ); //set window size

opencv = new OpenCV( this ); //setup openCV
opencv.capture( width, height ); // open video stream
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
}

void draw(){
opencv.read();
image(opencv.image(), 0, 0);
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
noFill();
  stroke(255,0,0);
  for( int i=0; i<faces.length; i++ ) {
    rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
  }
}

此代码可以工作几秒钟,然后发生异常。

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d961b22, pid=232, tid=4008
#
# JRE version: 6.0_33-b03
# Java VM: Java HotSpot(TM) Client VM (20.8-b03 mixed mode windows-x86 )
# Problematic frame:
# V  [jvm.dll+0xa1b22]
#
# An error report file with more information is saved as:
# C:\Documents and Settings\Administrator\Desktop\processing-2.0b7\hs_err_pid232.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

1 个答案:

答案 0 :(得分:0)

我认为这是opencv_core.CvMemStorage的内存分配问题。这是一个未在您的图书馆中公开的课程。我有同样的问题。我使用javacv(直接,而不是javacvpro),因为我想运行多个haar级联(你只能加载一个javacvpro或更老的hypermedia.video。*)。如果我在每个帧上运行所有这些,我很好。如果我在每个帧上运行不同的探测器(然后再通过探测器循环),我会在几个周期后得到这个错误。

FAILS下方的片段,但这是我想做的事情(使用不同的探测器处理每个后续帧):

// Using JavaCV directly, not JavaCVPro!
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
String cascades[] = {
  "haarcascade_eye.xml",            // 0
  "haarcascade_eye_tree_eyeglasses.xml",    // 1
  "haarcascade_frontalface_alt.xml"      // 2
}
int detectors[] = {1,3};
// haar detectors to use

String cascPath = "C:/opencv/data/haarcascades/";
// preload multiple classifiers. can do this with javacvpro, not with javacv or hypermedia.video.*

void haarSetup() {
    for (int i = 0; i < detectors.length; i++) {
      String classifierFile = cascPath+cascades[detectors[i]];
      classifier[i] = 
        new opencv_objdetect.CvHaarClassifierCascade(opencv_core.cvLoad(classifierFile));
    }
    storage = opencv_core.CvMemStorage.create();
    opencv_core.cvClearMemStorage(storage); // is this needed? couldn't hurt, right?
}

// contains list of preloaded haar cascades. code not included here...
opencv_core.CvSeq features[] = new opencv_core.CvSeq[detectors.length];
int whichHaar = 0;

// run one cascade per frame, then cycle through them.
void processHaars(PImage piz) {
  // convert to IplImage...  
  BufferedImage imgBuf = (BufferedImage) piz.getNative();    
  opencv_core.IplImage iplImgOut=opencv_core.IplImage.createFrom(imgBuf);
  // do one haar cascade per invocation.
  int ii = whichHaar;
  features[ii] = opencv_objdetect.cvHaarDetectObjects(iplImgOut, classifier[ii], storage, 1.1, 3, opencv_objdetect.CV_HAAR_DO_CANNY_PRUNING);
  whichHaar++;
  if (whichHaar >= detectors.length){
    whichHaar = 0;
    // is THIS causing the problem??
    opencv_core.cvClearMemStorage(storage);
  }
}

此代码片段永远有效,但我不想要它做什么(在一个帧上运行所有探测器):

void processHaars(PImage piz) {
// convert to IplImage...  
BufferedImage imgBuf = (BufferedImage) piz.getNative();    
opencv_core.IplImage iplImgOut=opencv_core.IplImage.createFrom(imgBuf);

for (ii=0; ii<detectors.length; ii++)
    faces[ii] = opencv_objdetect.cvHaarDetectObjects(iplImgOut, classifier[ii], storage, 1.1, 3, opencv_objdetect.CV_HAAR_DO_CANNY_PRUNING);

opencv_core.cvClearMemStorage(storage);
}

如果我找到完整的解决方案,我会发布它。