2013-01-05 63 views
0

我的處理代碼如下。EXCEPTION_ACCESS_VIOLATION(0xc0000005)在處理語言中使用OpenCV時

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

Hi @vishnu - 這段代碼是否會在其他機器上拋出相同的異常?你有沒有在你的機器上運行memtest(http://www.memtest.org/)以確保它沒有損壞RAM。我有類似的事情發生在我身上,這是我的臺式機上壞的RAM。 –

+0

我在朋友的筆記本電腦上運行了這段代碼,並得到了同樣的錯誤。 – vishnu

回答

0

我認爲這是opencv_core.CvMemStorage的內存分配問題。這是一個沒有在你的圖書館中暴露的類。我有同樣的問題。我正在使用javacv(直接,而不是javacvpro),因爲我想運行多個haar級聯(您只能使用javacvpro或較舊的hypermedia.video。*加載一個級聯)。如果我在每一幀都運行它們,我很好。如果我在每一幀上運行一個不同的探測器(然後再次循環探測器),我會在幾個週期後得到這個錯誤。

摘錄如下失敗了,但它確實是我想要做的(進程與不同的探測器每個後續幀):

// 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); 
    } 
} 

這個片段WORKS永遠,但我不希望它做什麼(在一個幀上運行所有檢測器):

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

如果我找到完整的解決方案,我會發布它。

相關問題