FaceDeDedition后的OutOfMemoryError package facerec; 导入java.awt.event.KeyAdapter; 导入java.awt.event.KeyEvent; 导入java.util.List; 导入javax.swing.JOptionPane; 导入javax.swing.SwingUtilities; 导入org.openimaj.feature.DoubleFVComparison; 导入org.openimaj.image.FImage; 导入org.openimaj.image.MBFImage; 导入org.openimaj.image.color.RGBColour; 导入org.openimaj.image.processing.face.alignment.rotateScaleAlligner; 导入org.openimaj.image.processing.face.detection.HaarCascadeDetector; 导入org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector; 导入org.openimaj.image.processing.face.detection.keypoints.KEDetectedFace; 导入org.openimaj.image.processing.face.recognition.eigenfacerecognizer; 导入org.openimaj.image.processing.face.recognition.FaceRecognitionEngine; 导入org.openimaj.image.typography.hershey.HersheyFont; 导入org.openimaj.math.geometry.point.Point2d; 导入org.openimaj.ml.annotation.Annotated; 导入org.openimaj.ml.annotation.AnnotatedObject; 导入org.openimaj.ml.annotation.scoredanotation; 导入org.openimaj.util.pair.IndependentPair; 导入org.openimaj.video.VideoDisplay; 导入org.openimaj.video.VideoDisplayListener; 导入org.openimaj.video.capture.VideoCapture; 公共类NewFaceRegister扩展KeyAdapter实现VideoDisplayListener{ 私人视频捕获; 专用视频显示视频帧; FKEFaceDetector faceDetector=新的FKEFaceDetector(新的HaarCascadeDetector()); 私有特征脸识别器识别器=特征脸识别器.create(20,新的RotateScaleAlligner(),1,DoubleFVComparison.CORRELATION,0.9f); FaceRecognitionEngine=FaceRecognitionEngine.create(faceDetector,Recognitor); 带注释的faceobj; 私有图像帧; public NewFaceRegister()引发异常{ 捕获=新的视频捕获(940720); //引擎=新的CLMFaceTracker(); //engine.fpd=120; videoFrame=VideoDisplay.createVideoDisplay(捕获); videoFrame.addVideoListener(此); SwingUtilities.getRoot(videoFrame.getScreen()).addKeyListener(this); } @凌驾 按下公共同步无效键(KeyEvent键){ if(key.getKeyCode()==KeyEvent.VK_空间){ 这个.videoFrame.togglePause(); }else if(key.getKeyChar(){ //如果(!this.videoFrame.isPaused()) //这个.videoFrame.togglePause(); 最后一个字符串person=JOptionPane.showInputDialog(this.videoFrame.getScreen(),“人名”和“,”, JOptionPane.QUESTION_消息); 最终列表面=detectFaces(); 如果(faces.size()==1){ 发动机。列车(面。获取(0),人); //TODO Datenbank Methode aufrufen,welches das AnnotatedObject(faceObj)speichert。 }否则{ 系统输出打印(“Zu viele/wenige Gesichter im Bild”); } //这个.videoFrame.close(); }否则 System.out.println(“错误的键”); } 私有列表detectFaces(){ 返回引擎.getDetector().detectFaces(currentFrame); } @凌驾 公共无效更新后(视频显示){ //无所事事 } @凌驾 更新之前的公共同步无效(MBFImage帧){ this.currentFrame=frame.flatte(); /*发动机、轨道(框架); engine.drawModel(帧,真,真,真,真,真)*/ 最终列表面=detectFaces(); 用于(检测到的面:面){ frame.drawShape(face.getBounds(),RGBColour.RED); } if(recogniser!=null&&recogniser.listPeople().size()>=1){ 用于(检测到的面:面){ 列表名称=engine.recognizeBest(face.getFacePatch()); 如果(name.size()>0){ final Point2d r=face.getBounds().getTopLeft(); frame.drawText(name.get(0.getSecondObject().toString(),r,HersheyFont.ROMAN_SIMPLEX,15,RGBColour.GREEN); } } } } 公共静态void main(字符串[]args)引发异常{ 新的NewFaceRegister(); } }
为什么会出现OutOfMemory错误?我用另一个Dedector试过了,结果成功了?!我也在其他问题中寻找答案,我找到了一个解决方案,我很努力地解决了它,但它也不起作用。 这是我第一次使用OpenimajFaceDeDedition后的OutOfMemoryError package facerec; 导入java.awt.event.KeyAdapter; 导入java.awt.event.KeyEvent; 导入java.util.List; 导入javax.swing.JOptionPane; 导入javax.swing.SwingUtilities; 导入org.openimaj.feature.DoubleFVComparison; 导入org.openimaj.image.FImage; 导入org.openimaj.image.MBFImage; 导入org.openimaj.image.color.RGBColour; 导入org.openimaj.image.processing.face.alignment.rotateScaleAlligner; 导入org.openimaj.image.processing.face.detection.HaarCascadeDetector; 导入org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector; 导入org.openimaj.image.processing.face.detection.keypoints.KEDetectedFace; 导入org.openimaj.image.processing.face.recognition.eigenfacerecognizer; 导入org.openimaj.image.processing.face.recognition.FaceRecognitionEngine; 导入org.openimaj.image.typography.hershey.HersheyFont; 导入org.openimaj.math.geometry.point.Point2d; 导入org.openimaj.ml.annotation.Annotated; 导入org.openimaj.ml.annotation.AnnotatedObject; 导入org.openimaj.ml.annotation.scoredanotation; 导入org.openimaj.util.pair.IndependentPair; 导入org.openimaj.video.VideoDisplay; 导入org.openimaj.video.VideoDisplayListener; 导入org.openimaj.video.capture.VideoCapture; 公共类NewFaceRegister扩展KeyAdapter实现VideoDisplayListener{ 私人视频捕获; 专用视频显示视频帧; FKEFaceDetector faceDetector=新的FKEFaceDetector(新的HaarCascadeDetector()); 私有特征脸识别器识别器=特征脸识别器.create(20,新的RotateScaleAlligner(),1,DoubleFVComparison.CORRELATION,0.9f); FaceRecognitionEngine=FaceRecognitionEngine.create(faceDetector,Recognitor); 带注释的faceobj; 私有图像帧; public NewFaceRegister()引发异常{ 捕获=新的视频捕获(940720); //引擎=新的CLMFaceTracker(); //engine.fpd=120; videoFrame=VideoDisplay.createVideoDisplay(捕获); videoFrame.addVideoListener(此); SwingUtilities.getRoot(videoFrame.getScreen()).addKeyListener(this); } @凌驾 按下公共同步无效键(KeyEvent键){ if(key.getKeyCode()==KeyEvent.VK_空间){ 这个.videoFrame.togglePause(); }else if(key.getKeyChar(){ //如果(!this.videoFrame.isPaused()) //这个.videoFrame.togglePause(); 最后一个字符串person=JOptionPane.showInputDialog(this.videoFrame.getScreen(),“人名”和“,”, JOptionPane.QUESTION_消息); 最终列表面=detectFaces(); 如果(faces.size()==1){ 发动机。列车(面。获取(0),人); //TODO Datenbank Methode aufrufen,welches das AnnotatedObject(faceObj)speichert。 }否则{ 系统输出打印(“Zu viele/wenige Gesichter im Bild”); } //这个.videoFrame.close(); }否则 System.out.println(“错误的键”); } 私有列表detectFaces(){ 返回引擎.getDetector().detectFaces(currentFrame); } @凌驾 公共无效更新后(视频显示){ //无所事事 } @凌驾 更新之前的公共同步无效(MBFImage帧){ this.currentFrame=frame.flatte(); /*发动机、轨道(框架); engine.drawModel(帧,真,真,真,真,真)*/ 最终列表面=detectFaces(); 用于(检测到的面:面){ frame.drawShape(face.getBounds(),RGBColour.RED); } if(recogniser!=null&&recogniser.listPeople().size()>=1){ 用于(检测到的面:面){ 列表名称=engine.recognizeBest(face.getFacePatch()); 如果(name.size()>0){ final Point2d r=face.getBounds().getTopLeft(); frame.drawText(name.get(0.getSecondObject().toString(),r,HersheyFont.ROMAN_SIMPLEX,15,RGBColour.GREEN); } } } } 公共静态void main(字符串[]args)引发异常{ 新的NewFaceRegister(); } },java,out-of-memory,face-detection,openimaj,Java,Out Of Memory,Face Detection,Openimaj,为什么会出现OutOfMemory错误?我用另一个Dedector试过了,结果成功了?!我也在其他问题中寻找答案,我找到了一个解决方案,我很努力地解决了它,但它也不起作用。 这是我第一次使用Openimaj package facerec; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.List; import javax.swing.JOptionPane; impor
package facerec;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.openimaj.feature.DoubleFVComparison;
import org.openimaj.image.FImage;
import org.openimaj.image.MBFImage;
import org.openimaj.image.colour.RGBColour;
import org.openimaj.image.processing.face.alignment.RotateScaleAligner;
import org.openimaj.image.processing.face.detection.HaarCascadeDetector;
import org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector;
import org.openimaj.image.processing.face.detection.keypoints.KEDetectedFace;
import org.openimaj.image.processing.face.recognition.EigenFaceRecogniser;
import org.openimaj.image.processing.face.recognition.FaceRecognitionEngine;
import org.openimaj.image.typography.hershey.HersheyFont;
import org.openimaj.math.geometry.point.Point2d;
import org.openimaj.ml.annotation.Annotated;
import org.openimaj.ml.annotation.AnnotatedObject;
import org.openimaj.ml.annotation.ScoredAnnotation;
import org.openimaj.util.pair.IndependentPair;
import org.openimaj.video.VideoDisplay;
import org.openimaj.video.VideoDisplayListener;
import org.openimaj.video.capture.VideoCapture;
public class NewFaceRegister extends KeyAdapter implements VideoDisplayListener<MBFImage> {
private VideoCapture capture;
private VideoDisplay<MBFImage> videoFrame;
FKEFaceDetector faceDetector = new FKEFaceDetector(new HaarCascadeDetector());
private EigenFaceRecogniser<KEDetectedFace, String> recogniser = EigenFaceRecogniser.create(20, new RotateScaleAligner(), 1, DoubleFVComparison.CORRELATION, 0.9f);
FaceRecognitionEngine<KEDetectedFace, String> engine = FaceRecognitionEngine.create(faceDetector, recogniser);
Annotated<KEDetectedFace, String> faceobj;
private FImage currentFrame;
public NewFaceRegister() throws Exception {
capture = new VideoCapture(940, 720);
//engine = new CLMFaceTracker();
//engine.fpd = 120;
videoFrame = VideoDisplay.createVideoDisplay(capture);
videoFrame.addVideoListener(this);
SwingUtilities.getRoot(videoFrame.getScreen()).addKeyListener(this);
}
@Override
public synchronized void keyPressed(KeyEvent key) {
if (key.getKeyCode() == KeyEvent.VK_SPACE) {
this.videoFrame.togglePause();
} else if (key.getKeyChar() == 'c') {
// if (!this.videoFrame.isPaused())
// this.videoFrame.togglePause();
final String person = JOptionPane.showInputDialog(this.videoFrame.getScreen(), "Name der Person eingeben", "",
JOptionPane.QUESTION_MESSAGE);
final List<KEDetectedFace> faces = detectFaces();
if (faces.size() == 1) {
engine.train(faces.get(0), person);
//TODO Datenbankmethode aufrufen, welches das AnnotatedObject (faceObj) speichert.
} else {
System.out.println("Zu viele/wenige Gesichter im Bild");
}
//this.videoFrame.close();
} else
System.out.println("Wrong key");
}
private List<KEDetectedFace> detectFaces() {
return engine.getDetector().detectFaces(currentFrame);
}
@Override
public void afterUpdate(VideoDisplay<MBFImage> display) {
// do nothing
}
@Override
public synchronized void beforeUpdate(MBFImage frame) {
this.currentFrame = frame.flatten();
/*engine.track(frame);
engine.drawModel(frame, true, true, true, true, true);*/
final List<KEDetectedFace> faces = detectFaces();
for (KEDetectedFace face : faces) {
frame.drawShape(face.getBounds(), RGBColour.RED);
}
if (recogniser != null && recogniser.listPeople().size() >= 1) {
for (KEDetectedFace face : faces) {
List<IndependentPair<KEDetectedFace, ScoredAnnotation<String>>> name = engine.recogniseBest(face.getFacePatch());
if (name.size() > 0) {
final Point2d r = face.getBounds().getTopLeft();
frame.drawText(name.get(0).getSecondObject().toString(), r, HersheyFont.ROMAN_SIMPLEX, 15, RGBColour.GREEN);
}
}
}
}
public static void main(String[] args) throws Exception {
new NewFaceRegister();
}
}
线程“thread-4”java.lang.OutOfMemoryError中的异常:java堆空间
位于no.uib.cipr.matrix.AbstractDensMatrix。(AbstractDensMatrix.java:47)
位于no.uib.cipr.matrix.DenseMatrix.(DenseMatrix.java:167)
位于no.uib.cipr.matrix.SVD.(SVD.java:98)
位于no.uib.cipr.matrix.SVD.(SVD.java:75)
编号为uib.cipr.matrix.SVD.factorize(SVD.java:146)
在org.openimaj.math.matrix.thinsinguedecomposition.(thinsinguedecomposition.java:84)
在org.openimaj.math.matrix.thinsinguedecomposition.(thinsinguedecomposition.java:69)
位于org.openimaj.math.matrix.algorithm.pca.ThinSvdPrincipalComponentAnalysis.learnBasisNorm(ThinSvdPrincipalComponentAnalysis.java:56)
位于org.openimaj.math.matrix.algorithm.pca.PrincipalComponentAnalysis.learnBasis(PrincipalComponentAnalysis.java:183)
位于org.openimaj.math.matrix.algorithm.pca.PrincipalComponentAnalysis.learnBasis(PrincipalComponentAnalysis.java:170)
位于org.openimaj.ml.pca.featurevectorpa.learnBasis(featurevectorpa.java:113)
位于org.openimaj.image.model.EigenImages.train(EigenImages.java:125)
位于org.openimaj.image.processing.face.feature.EigenFaceFeature$Extractor.train(EigenFaceFeature.java:167)
在org.openimaj.image.processing.face.recognition.EigenFaceRecogniser.beforeBatchTrain(EigenFaceRecogniser.java:159)上
在org.openimaj.image.processing.face.recognition.LazyFaceRecogniser.retain(LazyFaceRecogniser.java:139)上
位于org.openimaj.image.processing.face.recognition.LazyFaceRecogniser.annotate(LazyFaceRecogniser.java:153)
在org.ope
Exception in thread "Thread-4" java.lang.OutOfMemoryError: Java heap space
at no.uib.cipr.matrix.AbstractDenseMatrix.<init>(AbstractDenseMatrix.java:47)
at no.uib.cipr.matrix.DenseMatrix.<init>(DenseMatrix.java:167)
at no.uib.cipr.matrix.SVD.<init>(SVD.java:98)
at no.uib.cipr.matrix.SVD.<init>(SVD.java:75)
at no.uib.cipr.matrix.SVD.factorize(SVD.java:146)
at org.openimaj.math.matrix.ThinSingularValueDecomposition.<init>(ThinSingularValueDecomposition.java:84)
at org.openimaj.math.matrix.ThinSingularValueDecomposition.<init>(ThinSingularValueDecomposition.java:69)
at org.openimaj.math.matrix.algorithm.pca.ThinSvdPrincipalComponentAnalysis.learnBasisNorm(ThinSvdPrincipalComponentAnalysis.java:56)
at org.openimaj.math.matrix.algorithm.pca.PrincipalComponentAnalysis.learnBasis(PrincipalComponentAnalysis.java:183)
at org.openimaj.math.matrix.algorithm.pca.PrincipalComponentAnalysis.learnBasis(PrincipalComponentAnalysis.java:170)
at org.openimaj.ml.pca.FeatureVectorPCA.learnBasis(FeatureVectorPCA.java:113)
at org.openimaj.image.model.EigenImages.train(EigenImages.java:125)
at org.openimaj.image.processing.face.feature.EigenFaceFeature$Extractor.train(EigenFaceFeature.java:167)
at org.openimaj.image.processing.face.recognition.EigenFaceRecogniser.beforeBatchTrain(EigenFaceRecogniser.java:159)
at org.openimaj.image.processing.face.recognition.LazyFaceRecogniser.retrain(LazyFaceRecogniser.java:139)
at org.openimaj.image.processing.face.recognition.LazyFaceRecogniser.annotate(LazyFaceRecogniser.java:153)
at org.openimaj.image.processing.face.recognition.EigenFaceRecogniser.annotate(EigenFaceRecogniser.java:55)
at org.openimaj.image.processing.face.recognition.FaceRecogniser.annotateBest(FaceRecogniser.java:115)
at org.openimaj.image.processing.face.recognition.FaceRecognitionEngine.recogniseBest(FaceRecognitionEngine.java:260)
at facerec.NewFaceRegister.beforeUpdate(NewFaceRegister.java:97)
at facerec.NewFaceRegister.beforeUpdate(NewFaceRegister.java:1)
at org.openimaj.video.VideoDisplay.fireBeforeUpdate(VideoDisplay.java:785)
at org.openimaj.video.VideoDisplay.run(VideoDisplay.java:522)
at java.lang.Thread.run(Unknown Source)