UtilsFragments.java
Go to the documentation of this file.
1 package com.intel.realsense.capture;
2 
3 import android.Manifest;
4 import android.content.Context;
5 import android.content.pm.PackageManager;
6 import android.os.Bundle;
7 import android.os.Handler;
8 import androidx.core.app.ActivityCompat;
9 import androidx.core.content.ContextCompat;
10 import androidx.appcompat.app.AppCompatActivity;
11 import android.util.Log;
12 import android.view.View;
13 import android.widget.TextView;
14 
32 
33 // Aim of this fragment is to show how the following functions must be used:
34 // From class Utils:
35 // deprojectPixelToPoint
36 // transformPointToPoint
37 // projectPointToPixel
38 // getFov
39 // project2dPixelToDepthPixel
40 
41 
42 private int framesCounter = 1;
43  Runnable mStreaming = new Runnable() {
44 @Override
45 public void run() {
46  try {
47  try(FrameSet frames = mPipeline.waitForFrames()) {
48  try(FrameSet processed = frames.applyFilter(mColorizer)) {
49  mGLSurfaceView.upload(processed);
50  if((++framesCounter % 80) == 0) {
51  // getting depth frame
52  DepthFrame depthFrame = frames.first(StreamType.DEPTH).as(Extension.DEPTH_FRAME);
53  Intrinsic depthFrameIntrinsic = depthFrame.getProfile().getIntrinsic();
54  // getting depth frame field of view
55  float fov[] = Utils.getFov(depthFrameIntrinsic);
56  Log.d(TAG, "fov = (" + fov[0] + ", " + fov[1] + ")");
57  // getting color frame
58  VideoFrame colorFrame = frames.first(StreamType.COLOR).as(Extension.VIDEO_FRAME);
59  Intrinsic colorFrameIntrinsic = colorFrame.getProfile().getIntrinsic();
60  // computing extrinsics between the profiles
61  Extrinsic depthToColorExtrinsic = depthFrame.getProfile().getExtrinsicTo(colorFrame.getProfile());
62  Extrinsic colorToDepthExtrinsic = colorFrame.getProfile().getExtrinsicTo(depthFrame.getProfile());
63  // finding depth pixel with distance not zero (means that there is depth data in this pixel)
64  int w = depthFrameIntrinsic.getWidth();
65  int h = depthFrameIntrinsic.getHeight();
66  byte[] depthFrameData = new byte[ w * h ];
67  depthFrame.getData(depthFrameData);
68  float depthDataAtMiddleOfFrame = depthFrameData[w * h / 2];
69  int halfWidth = w / 2;
70  while (depthDataAtMiddleOfFrame < 0.2) {
71  halfWidth += 10;
72  depthDataAtMiddleOfFrame = depthFrameData[halfWidth * h];
73  }
74  // using get distance api to convert from raw distance to meters
75  float depthAtMiddleOfFrame = depthFrame.getDistance(halfWidth, h / 2);
76  Log.d(TAG, "depth = " + depthAtMiddleOfFrame);
77  // deproject, transform, project - in order to convert from depth pixel to color pixel
78  Pixel depth_pixel = new Pixel(halfWidth, h/2);
79  Point_3D depth_point = Utils.deprojectPixelToPoint(depthFrameIntrinsic, depth_pixel, depthAtMiddleOfFrame );
80  Point_3D color_point = Utils.transformPointToPoint(depthToColorExtrinsic, depth_point );
81  Pixel color_pixel = Utils.projectPointToPixel(colorFrameIntrinsic, color_point);
82  Log.d(TAG, "depthPoint = (" + depth_point.mX + ", " + depth_point.mY + ", " + depth_point.mZ + ")");
83  Log.d(TAG, "colorPoint = (" + color_point.mX + ", " + color_point.mY + ", " + color_point.mZ + ")");
84  Log.d(TAG, "pixel = (" + depth_pixel.mX + ", " + depth_pixel.mY + ")");
85  Log.d(TAG, "color pixel = (" + color_pixel.mX + ", " + color_pixel.mY + ")");
86  // convert color pixel to depth pixel
87  float depthMin = 0.1f;
88  float depthMax = 10.f;
89  Pixel toPixel = Utils.project2dPixelToDepthPixel(depthFrame, mDepthScale, depthMin, depthMax,
90  depthFrameIntrinsic, colorFrameIntrinsic, colorToDepthExtrinsic, depthToColorExtrinsic, color_pixel);
91  Log.d(TAG, "to_pixel = (" + toPixel.mX + ", " + toPixel.mY + ")");
92  }
93  }
94  }
95  mHandler.post(mStreaming);
96  }
97  catch (Exception e) {
98  Log.e(TAG, "streaming, error: " + e.getMessage());
99  }
100  }
101 };
::rosgraph_msgs::Log_< std::allocator< void > > Log
Definition: Log.h:88
GLdouble GLdouble GLdouble w
Extrinsic getExtrinsicTo(StreamProfile other)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
e
Definition: rmse.py:177
static float[] getFov(final Intrinsic intrinsic)
Definition: Utils.java:39
def run(include_folder_path, addon_folder_path)
Definition: enums.py:46
static Pixel projectPointToPixel(final Intrinsic intrinsic, final Point_3D point)
Definition: Utils.java:8
static Pixel project2dPixelToDepthPixel(final DepthFrame depthFrame, float depthScale, float depthMin, float depthMax, final Intrinsic depthIntrinsic, final Intrinsic otherIntrinsic, final Extrinsic otherToDepth, final Extrinsic depthToOther, final Pixel fromPixel)
Definition: Utils.java:48
static Point_3D deprojectPixelToPoint(final Intrinsic intrinsic, final Pixel pixel, final float depth)
Definition: Utils.java:16
unsigned char byte
Definition: src/types.h:52
static Point_3D transformPointToPoint(final Extrinsic extrinsic, final Point_3D from_point)
Definition: Utils.java:23


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:13