Javacv人脸识别



我正在尝试使用faceerrecognition与javacv。但是当我有超过5个火车图像时,我得到这个错误:

# Java运行时环境检测到致命错误:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6a30b400, pid=4856, tid=32
#
JRE版本:Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) Client VM (24.51-b03混合模式,共享windows-x86)
#问题框架:
# C [opencv_core246.dll+0x4b400]
#
写核心转储失败。默认情况下,Windows客户端版本不启用迷你转储
#
包含更多信息的错误报告文件被保存为:
# C:Usersrecoworkspacehellow hs_err_pid4856.log
#
#如果您想提交错误报告,请访问:
# http://bugreport.sun.com/bugreport/crash.jsp
#崩溃发生在Java虚拟机之外的本机代码中。
#查看问题框架,查看报告错误的位置。
#

这是我的代码:

import com.googlecode.javacv.cpp.opencv_core;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_contrib.*;
import java.io.File;
import java.io.FilenameFilter;
public class OpenCVFaceRecognizer {
public static void main(String[] args) {
    String trainingDir = "C:/Users/reco/workspace/hellow";
    IplImage testImage = cvLoadImage("C:/Users/reco/workspace/0.png");
    File root = new File(trainingDir);
    FilenameFilter pngFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".png");
        }
    };
    File[] imageFiles = root.listFiles(pngFilter);
     MatVector images = new MatVector(imageFiles.length);
    int[] labels = new int[imageFiles.length];
    int counter = 0;
    int label;
    IplImage img;
    IplImage grayImg;
    for (File image : imageFiles) {
        img = cvLoadImage(image.getAbsolutePath());
        String temp= image.getName();
        label = Integer.parseInt(temp.charAt(0)+"");
        grayImg = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1);
        cvCvtColor(img, grayImg, CV_BGR2GRAY);
        images.put(counter, grayImg);
        labels[counter] = label;
        counter++;
    }
    IplImage greyTestImage = IplImage.create(testImage.width(), testImage.height(), IPL_DEPTH_8U, 1);
    //FaceRecognizer faceRecognizer = createFisherFaceRecognizer();
     FaceRecognizer faceRecognizer = createEigenFaceRecognizer();
    // FaceRecognizer faceRecognizer = createLBPHFaceRecognizer()
    faceRecognizer.train(images, labels);
    cvCvtColor(testImage, greyTestImage, CV_BGR2GRAY);
    int predictedLabel = faceRecognizer.predict(greyTestImage);
    System.out.println("Predicted label: " + predictedLabel);
}
}

edit::i just remove

    grayImg = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1);
    cvCvtColor(img, grayImg, CV_BGR2GRAY);

    IplImage img;
    IplImage grayImg=null;
    for (File image : imageFiles) {
        img = cvLoadImage(image.getAbsolutePath(),CV_BGR2GRAY);
        int yer = image.getName().indexOf(".");
        String isim=image.getName().substring(0,yer);
        label = Integer.parseInt(isim);
        images.put(counter, img);
        labels[counter] = label;
        counter++;
    }

它是我的代码的最后一个,它像一个魅力:)

相关内容

  • 没有找到相关文章

最新更新