Java、Kinect(OpenNI)、Processingを使った実際のプロジェクトに問題があります。
処理とJavaだけを使用すると、すべてが正常に機能し、つまずくことはなく、例外も発生しません。
しかし、(アプレットスタイルの処理に関するいくつかの問題を解決するために)JFrameで処理アプレットを投獄すると、次の問題が発生します。
- 3秒ごとにkinectイメージがすぐにハングします(Javaがガベージコレクターを使用してメモリから何かをクリアしているように見えます)
20秒後、アプリケーションが停止し、次のエラーが発生します。
Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(Unknown Source) at java.awt.image.Raster.createPackedRaster(Unknown Source) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source) at java.awt.image.BufferedImage.<init>(Unknown Source)
視覚化に関する私の関連コードは次のとおりです。
public boolean drawGrayscaleImage(){
//init PApplet and build JFrame
GrayscalePApplet grayscalePApplet = new GrayscalePApplet ();
grayscalePApplet.init();
this.grayscaleJFrame = this.initFrame(grayscalePApplet);
//Set Uplink for PApplet and begin drawing
grayscalePApplet.setGraphicP(this);
return false;
}
ここでは、ProcessingPAppletクラスからの描画関数です。
public void draw(){
if(graphicP != null){
//creat the relevant image Buffers for java and Processing
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_BYTE_GRAY);
PImage pimage = new PImage(image.getWidth(),image.getHeight(),PConstants.ARGB);
//fill up the databuffer using a converted Kinect Grayscale Image
DataBufferByte dataBuffer = new DataBufferByte(graphicP.getImage(ImageType.GRAYSCALE), this.imageWidth * this.imageHeight);
Raster raster = Raster.createPackedRaster(dataBuffer,imageWidth, imageHeight, 8, null);
image.setData(raster);
//draw image to Processing
image.getRGB(0, 0, pimage.width, pimage.height, pimage.pixels, 0, pimage.width);
pimage.updatePixels();
image(pimage, 0, 0);
// null everything to get Garbagecollection to work (?)
image = null;
pimage = null;
dataBuffer = null;
}
}
そのOutOfMemory例外を防ぐにはどうすればよいですか?
その例外の原因は何ですか?