TOF_ImageReader.java
Go to the documentation of this file.
1 package com.introlab.rtabmap;
2 
3 
4 import android.graphics.ImageFormat;
5 import android.media.Image;
6 import android.media.ImageReader;
7 import android.os.Handler;
8 import android.os.HandlerThread;
9 import android.util.Log;
10 
11 import java.nio.ByteBuffer;
12 
13 public class TOF_ImageReader implements ImageReader.OnImageAvailableListener {
14 
15  public int WIDTH;
16  public int HEIGHT;
17  public ImageReader imageReader;
18  public int frameCount = 0;
19  public long timestamp;
20 
21  // Looper handler thread.
22  private HandlerThread backgroundThread;
23  // Looper handler.
24  private Handler backgroundHandler;
25 
26  public ByteBuffer depth16_raw;
27 
29  }
30 
31  public void createImageReader(int width, int height){
32  this.WIDTH = width;
33  this.HEIGHT = height;
34  this.imageReader =
35  ImageReader.newInstance(
36  width,
37  height,
38  ImageFormat.DEPTH16,
39  2);
40  this.imageReader.setOnImageAvailableListener(this, this.backgroundHandler);
41  }
42 
43  // CPU image reader callback.
44  @Override
45  public void onImageAvailable(ImageReader imageReader) {
46  Image image = imageReader.acquireLatestImage();
47  if (image == null) {
48  Log.w("RTABMapActivity", "onImageAvailable: Skipping null image.");
49  return;
50  }
51  else{
52  if(image.getFormat() == ImageFormat.DEPTH16){
53  this.timestamp = image.getTimestamp();
54  depth16_raw = image.getPlanes()[0].getBuffer().asReadOnlyBuffer();
55  // copy raw undecoded DEPTH16 format depth data to NativeBuffer
56  frameCount++;
57  }
58  else{
59  Log.w("RTABMapActivity", "onImageAvailable: depth image not in DEPTH16 format, skipping image");
60  }
61  }
62  image.close();
63  }
64 
65  // Start background handler thread, used to run callbacks without blocking UI thread.
66  public void startBackgroundThread() {
67  this.backgroundThread = new HandlerThread("DepthDecoderThread");
68  this.backgroundThread.start();
69  this.backgroundHandler = new Handler(backgroundThread.getLooper());
70  }
71 
72  // Stop background handler thread.
73  public void stopBackgroundThread() {
74  if (this.backgroundThread != null) {
75  this.backgroundThread.quitSafely();
76  try {
77  this.backgroundThread.join();
78  this.backgroundThread = null;
79  this.backgroundHandler = null;
80  } catch (InterruptedException e) {
81  Log.e("RTABMapActivity", "Interrupted while trying to join depth background handler thread", e);
82  }
83  }
84  }
85 
86 }
87 
GLM_FUNC_DECL genType e()
void onImageAvailable(ImageReader imageReader)
void createImageReader(int width, int height)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:37:06