rs-color.c
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 /* Include the librealsense C header files */
5 #include <librealsense2/rs.h>
8 
9 #include <stdlib.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include "example.h"
13 
14 
16 // These parameters are reconfigurable //
18 #define STREAM RS2_STREAM_COLOR // rs2_stream is a types of data provided by RealSense device //
19 #define FORMAT RS2_FORMAT_RGB8 // rs2_format identifies how binary data is encoded within a frame //
20 #define WIDTH 640 // Defines the number of columns for each frame //
21 #define HEIGHT 480 // Defines the number of lines for each frame //
22 #define FPS 30 // Defines the rate of frames per second //
23 #define STREAM_INDEX 0 // Defines the stream index, used for multiple streams of the same type //
24 
26 
27 int main()
28 {
29  rs2_error* e = 0;
30 
31  // Create a context object. This object owns the handles to all connected realsense devices.
32  // The returned object should be released with rs2_delete_context(...)
34  check_error(e);
35 
36  /* Get a list of all the connected devices. */
37  // The returned object should be released with rs2_delete_device_list(...)
38  rs2_device_list* device_list = rs2_query_devices(ctx, &e);
39  check_error(e);
40 
41  int dev_count = rs2_get_device_count(device_list, &e);
42  check_error(e);
43  printf("There are %d connected RealSense devices.\n", dev_count);
44  if (0 == dev_count)
45  return EXIT_FAILURE;
46 
47  // Get the first connected device
48  // The returned object should be released with rs2_delete_device(...)
49  rs2_device* dev = rs2_create_device(device_list, 0, &e);
50  check_error(e);
51 
52  print_device_info(dev);
53 
54  // Create a pipeline to configure, start and stop camera streaming
55  // The returned object should be released with rs2_delete_pipeline(...)
57  check_error(e);
58 
59  // Create a config instance, used to specify hardware configuration
60  // The retunred object should be released with rs2_delete_config(...)
62  check_error(e);
63 
64  // Request a specific configuration
66  check_error(e);
67 
68  // Start the pipeline streaming
69  // The retunred object should be released with rs2_delete_pipeline_profile(...)
71  if (e)
72  {
73  printf("The connected device doesn't support color streaming!\n");
74  exit(EXIT_FAILURE);
75  }
76 
77  while (1)
78  {
79  // This call waits until a new composite_frame is available
80  // composite_frame holds a set of frames. It is used to prevent frame drops
81  // The returned object should be released with rs2_release_frame(...)
83  check_error(e);
84 
85  // Returns the number of frames embedded within the composite frame
86  int num_of_frames = rs2_embedded_frames_count(frames, &e);
87  check_error(e);
88 
89  int i;
90  for (i = 0; i < num_of_frames; ++i)
91  {
92  // The retunred object should be released with rs2_release_frame(...)
93  rs2_frame* frame = rs2_extract_frame(frames, i, &e);
94  check_error(e);
95 
96  const uint8_t* rgb_frame_data = (const uint8_t*)(rs2_get_frame_data(frame, &e));
97  check_error(e);
98 
99  unsigned long long frame_number = rs2_get_frame_number(frame, &e);
100  check_error(e);
101 
103  check_error(e);
104 
105  // Specifies the clock in relation to which the frame timestamp was measured
106  rs2_timestamp_domain frame_timestamp_domain = rs2_get_frame_timestamp_domain(frame, &e);
107  check_error(e);
108  const char* frame_timestamp_domain_str = rs2_timestamp_domain_to_string(frame_timestamp_domain);
109 
110  rs2_metadata_type frame_metadata_time_of_arrival = rs2_get_frame_metadata(frame, RS2_FRAME_METADATA_TIME_OF_ARRIVAL, &e);
111  check_error(e);
112 
113  printf("RGB frame arrived.\n");
114  printf("First 10 bytes: ");
115  int i;
116  for(i=0; i < 10; ++i)
117  printf("%02x ", rgb_frame_data[i]);
118 
119  printf("\nFrame No: %llu\n", frame_number);
120  printf("Timestamp: %f\n", frame_timestamp);
121  printf("Timestamp domain: %s\n", frame_timestamp_domain_str);
122  printf("Time of arrival: %lld\n\n", frame_metadata_time_of_arrival);
123  rs2_release_frame(frame);
124  }
125 
126  rs2_release_frame(frames);
127  }
128 
129  // Stop the pipeline streaming
130  rs2_pipeline_stop(pipeline, &e);
131  check_error(e);
132 
133  // Release resources
134  rs2_delete_pipeline_profile(pipeline_profile);
135  rs2_delete_config(config);
136  rs2_delete_pipeline(pipeline);
137  rs2_delete_device(dev);
138  rs2_delete_device_list(device_list);
139  rs2_delete_context(ctx);
140 
141  return EXIT_SUCCESS;
142 }
void rs2_config_enable_stream(rs2_config *config, rs2_stream stream, int index, int width, int height, rs2_format format, int framerate, rs2_error **error)
Definition: rs.cpp:1928
void print_device_info(rs2_device *dev)
Definition: example.h:19
Exposes RealSense processing-block functionality for C compilers.
#define RS2_API_VERSION
Definition: rs.h:41
rs2_device_list * rs2_query_devices(const rs2_context *context, rs2_error **error)
Definition: rs.cpp:208
const char * rs2_timestamp_domain_to_string(rs2_timestamp_domain info)
Definition: rs.cpp:1267
void rs2_delete_device(rs2_device *device)
Definition: rs.cpp:301
rs2_context * rs2_create_context(int api_version, rs2_error **error)
Creates RealSense context that is required for the rest of the API.
Definition: rs.cpp:163
rs2_config * rs2_create_config(rs2_error **error)
Definition: rs.cpp:1914
void rs2_delete_context(rs2_context *context)
Frees the relevant context object.
Definition: rs.cpp:171
rs2_pipeline * rs2_create_pipeline(rs2_context *ctx, rs2_error **error)
Definition: rs.cpp:1756
rs2_device * rs2_create_device(const rs2_device_list *info_list, int index, rs2_error **error)
Definition: rs.cpp:289
rs2_time_t rs2_get_frame_timestamp(const rs2_frame *frame, rs2_error **error)
Definition: rs.cpp:908
unsigned char uint8_t
Definition: stdint.h:78
void check_error(rs2_error *e)
Definition: example.h:9
e
Definition: rmse.py:177
Exposes librealsense functionality for C compilers.
int main()
Definition: rs-color.c:27
#define HEIGHT
Definition: rs-color.c:21
rs2_frame * rs2_pipeline_wait_for_frames(rs2_pipeline *pipe, unsigned int timeout_ms, rs2_error **error)
Definition: rs.cpp:1774
Exposes RealSense frame functionality for C compilers.
int rs2_embedded_frames_count(rs2_frame *composite, rs2_error **error)
Definition: rs.cpp:2144
#define FPS
Definition: rs-color.c:22
rs2_timestamp_domain rs2_get_frame_timestamp_domain(const rs2_frame *frameset, rs2_error **error)
Definition: rs.cpp:915
Definition: api.h:28
#define RS2_DEFAULT_TIMEOUT
Definition: rs_config.h:13
unsigned long long rs2_get_frame_number(const rs2_frame *frame, rs2_error **error)
Definition: rs.cpp:986
static const textual_icon exit
Definition: model-views.h:254
rs2_pipeline_profile * rs2_pipeline_start_with_config(rs2_pipeline *pipe, rs2_config *config, rs2_error **error)
Definition: rs.cpp:1834
long long rs2_metadata_type
Definition: rs_types.h:301
void rs2_pipeline_stop(rs2_pipeline *pipe, rs2_error **error)
Definition: rs.cpp:1766
void rs2_delete_config(rs2_config *config)
Definition: rs.cpp:1920
int i
void rs2_release_frame(rs2_frame *frame)
Definition: rs.cpp:993
rs2_frame * rs2_extract_frame(rs2_frame *composite, int index, rs2_error **error)
Definition: rs.cpp:2114
rs2_metadata_type rs2_get_frame_metadata(const rs2_frame *frame, rs2_frame_metadata_value frame_metadata, rs2_error **error)
Definition: rs.cpp:846
double rs2_time_t
Definition: rs_types.h:300
#define STREAM
Definition: rs-color.c:18
void rs2_delete_device_list(rs2_device_list *info_list)
Definition: rs.cpp:275
void rs2_delete_pipeline_profile(rs2_pipeline_profile *profile)
Definition: rs.cpp:1905
int rs2_get_device_count(const rs2_device_list *info_list, rs2_error **error)
Definition: rs.cpp:259
#define FORMAT
Definition: rs-color.c:19
void rs2_delete_pipeline(rs2_pipeline *pipe)
Definition: rs.cpp:1819
struct rs2_frame rs2_frame
Definition: rs_types.h:261
const void * rs2_get_frame_data(const rs2_frame *frame, rs2_error **error)
Definition: rs.cpp:940
#define WIDTH
Definition: rs-color.c:20
#define STREAM_INDEX
Definition: rs-color.c:23
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19


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