2013-03-06 3 views
0

J'essaie d'enregistrer des fichiers oni avec Java. Cela fonctionne bien quand j'enregistre un fichier. Mais quand je veux enregistrer plusieurs fichiers, je rencontre des problèmes.Impossible de réenregistrer un fichier oni

Voici un code de test:

package test; 

import org.OpenNI.Context; 
import org.OpenNI.DepthGenerator; 
import org.OpenNI.GeneralException; 
import org.OpenNI.ImageGenerator; 
import org.OpenNI.OutArg; 
import org.OpenNI.RecordMedium; 
import org.OpenNI.Recorder; 
import org.OpenNI.ScriptNode; 

public class RecorderProblems { 

    private static final String SAMPLE_XML_FILE = "KinectConfig.xml"; 
    private static final String TEST1_ONI_FILE = "Test1.oni"; 
    private static final String TEST2_ONI_FILE = "Test2.oni"; 

    public static void main(String[] args) { 
     Context context = null; 
     DepthGenerator depthGenerator = null; 
     ImageGenerator imageGenerator = null; 
     try { 
      OutArg<ScriptNode> scriptNode = new OutArg<ScriptNode>(); 

      // Init Hardware 
      System.out.println("Init Hardware"); 
      context = Context.createFromXmlFile(SAMPLE_XML_FILE, scriptNode); 
      depthGenerator = DepthGenerator.create(context); 
      imageGenerator = ImageGenerator.create(context); 
      context.startGeneratingAll(); 

      // Record 1 
      System.out.println("Start Record 1"); 
      Recorder recorder = Recorder.create(context, "oni"); 
      // Adding next line produces a corrupt file, but the program runs fine 
//   context.createProductionTree(recorder.getInfo()); 
      recorder.setDestination(RecordMedium.FILE, TEST1_ONI_FILE); 
      recorder.addNodeToRecording(depthGenerator); 
      recorder.addNodeToRecording(imageGenerator); 
      for (int i = 0; i < 100; i++) { 
       context.waitOneUpdateAll(imageGenerator); 
       recorder.Record(); 
      } 
      recorder.removeNodeToRecording(depthGenerator); 
      recorder.removeNodeToRecording(imageGenerator); 
      recorder.dispose(); 

      // Record 2 
      System.out.println("Start Record 2"); 
      recorder = Recorder.create(context, "oni"); 
      // Adding next line produces a corrupt file, but the program runs fine 
//   context.createProductionTree(recorder.getInfo()); 
      recorder.setDestination(RecordMedium.FILE, TEST2_ONI_FILE); 
      recorder.addNodeToRecording(depthGenerator); 
      recorder.addNodeToRecording(imageGenerator); 
      for (int i = 0; i < 100; i++) { 
       context.waitOneUpdateAll(imageGenerator); 
       recorder.Record(); 
      } 
      recorder.removeNodeToRecording(depthGenerator); 
      recorder.removeNodeToRecording(imageGenerator); 
      recorder.dispose(); 
     } catch (GeneralException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } finally { 
      // End Hardware 
      System.out.println("End Hardware"); 
      depthGenerator.dispose(); 
      depthGenerator = null; 
      imageGenerator.dispose(); 
      imageGenerator = null; 
      context.release(); 
      context.dispose(); 
     } 
    } 
} 

Lorsque je tente de définir la destination pour le deuxième disque que je reçois un StatusException « pointeur d'entrée est nulle ».

Si j'ajoute la ligne non commentée, le programme s'exécute correctement, mais les fichiers oni créés ne sont pas lisibles. (Je ne sais pas exactement ce que fait la ligne.)

J'ai également essayé de réinitialiser le contexte. Au début, cela fonctionnait bien, mais quand j'ai essayé d'enregistrer plusieurs fichiers, j'ai aussi eu des problèmes lors de la réinitialisation. Voici quelques exemples de code: « Un délai d'attente a eu lieu lors de l'attente de nouvelles données »

package test; 

import org.OpenNI.Context; 
import org.OpenNI.DepthGenerator; 
import org.OpenNI.GeneralException; 
import org.OpenNI.ImageGenerator; 
import org.OpenNI.OutArg; 
import org.OpenNI.RecordMedium; 
import org.OpenNI.Recorder; 
import org.OpenNI.ScriptNode; 

public class RecorderProblems { 

    private static final String SAMPLE_XML_FILE = "KinectConfig.xml"; 

    public static void main(String[] args) { 
     Context context = null; 
     DepthGenerator depthGenerator = null; 
     ImageGenerator imageGenerator = null; 
     try { 
      OutArg<ScriptNode> scriptNode = new OutArg<ScriptNode>(); 

      // Record 1 
      for (int i = 0; i < 25; i++) { 
       System.out.println("Run " + i); 
       // Init Hardware 
       System.out.println("Init Hardware " + i); 
       context = Context 
         .createFromXmlFile(SAMPLE_XML_FILE, scriptNode); 
       depthGenerator = DepthGenerator.create(context); 
       imageGenerator = ImageGenerator.create(context); 
       context.startGeneratingAll(); 

       System.out.println("Start Record " + i); 
       Recorder recorder = Recorder.create(context, "oni"); 
       recorder.setDestination(RecordMedium.FILE, "test_" + i + ".oni"); 
       recorder.addNodeToRecording(depthGenerator); 
       recorder.addNodeToRecording(imageGenerator); 
       for (int j = 0; j < 100; j++) { 
        context.waitOneUpdateAll(imageGenerator); 
        recorder.Record(); 
       } 
       recorder.removeNodeToRecording(depthGenerator); 
       recorder.removeNodeToRecording(imageGenerator); 
       recorder.dispose(); 

       System.out.println("End Hardware " + i); 
       depthGenerator.dispose(); 
       depthGenerator = null; 
       imageGenerator.dispose(); 
       imageGenerator = null; 
       context.release(); 
       context.dispose(); 
      } 

     } catch (GeneralException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
} 

Le troisième manche, je suis un StatusExcption.

Est-ce que quelqu'un a déjà essayé l'enregistrement de fichiers? Je ne sais pas si, j'utilise la mauvaise bibliothèque, ou si c'est un problème d'OpenNI (avec Java)? Par ailleurs, j'utilise OpenNI 1.5.2.23 et la caméra Kinect. Le fichier de configuration XML "KinectConfig.xml" est le fichier XML par défaut fourni avec les exemples OpenNI. Je viens de le renommer.

Merci pour votre aide

Répondre

0

Pourquoi faites-vous ce si compliqué? Vous pouvez utiliser Android libraries pour cela.

+0

J'ai besoin du format de fichier oni. Les fichiers oni créés doivent être traités avec une bibliothèque existante qui nécessite des fichiers oni en entrée. Je pense que cette bibliothèque ne supporte pas oni, ou je l'ai dépassé? – hami

0

J'ai le problème de lire la profondeur de résolution VGA et rgb pariant la même erreur de timeout. Si je réduis la résolution de profondeur ou RVB au quart vga tout fonctionne.

Questions connexes