Skip to content

Commit

Permalink
[sample][update]: update library dependencies and header file configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
daiyin committed Jun 18, 2024
1 parent 7d0e2b0 commit 4c704b3
Show file tree
Hide file tree
Showing 27 changed files with 57 additions and 73 deletions.
2 changes: 1 addition & 1 deletion examples/0.basic.enumerate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_enumerate)
add_executable(ob_enumerate enumerate.cpp)

set_property(TARGET ob_enumerate PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_enumerate OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_enumerate ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties (ob_enumerate PROPERTIES FOLDER "Examples")

# ob_install_example_target(ob_enumerate)
Expand Down
4 changes: 2 additions & 2 deletions examples/0.basic.enumerate/enumerate.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "window.hpp"

#include <iostream>
#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"

#include <openobsdk/ObSensor.h>

const char* sensorTypes[] = {
"OB_SENSOR_UNKNOWN",
Expand Down
2 changes: 1 addition & 1 deletion examples/0.basic.quick_start/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_quick_start)
add_executable(ob_quick_start quick_start.cpp)

set_property(TARGET ob_quick_start PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_quick_start openobsdk ${OpenCV_LIBS})
target_link_libraries(ob_quick_start ob::openobsdk ob::examples::common ${OpenCV_LIBS})

set_target_properties (ob_quick_start PROPERTIES FOLDER "Examples")

Expand Down
3 changes: 1 addition & 2 deletions examples/0.basic.quick_start/quick_start.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "window.hpp"
#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>
// #include "utils.hpp"

int main(int argc, char **argv) try {
Expand Down
2 changes: 1 addition & 1 deletion examples/1.stream.color/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include_directories(${CMAKE_SOURCE_DIR}/include/openobsdk)
add_executable(ob_color color.cpp)

set_property(TARGET ob_color PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_color OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_color ob::openobsdk ob::examples::common ${OpenCV_LIBS})

set_target_properties (ob_color PROPERTIES FOLDER "Examples")

Expand Down
3 changes: 1 addition & 2 deletions examples/1.stream.color/color.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "window.hpp"

#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>

const char* metaDataTypes[] = {
"OB_FRAME_METADATA_TYPE_TIMESTAMP",
Expand Down
2 changes: 1 addition & 1 deletion examples/1.stream.depth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_depth)
add_executable(ob_depth depth.cpp)

set_property(TARGET ob_depth PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_depth OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_depth ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties(ob_depth PROPERTIES FOLDER "Examples")

# ob_install_example_target(ob_depth) ob_install_example_current_source("/cpp/1.stream.depth")
3 changes: 1 addition & 2 deletions examples/1.stream.depth/depth.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "window.hpp"

#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>

int main(int argc, char **argv) try {

Expand Down
2 changes: 1 addition & 1 deletion examples/1.stream.imu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_imu)
add_executable(ob_imu imu.cpp)

set_property(TARGET ob_imu PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_imu OrbbecSDK)
target_link_libraries(ob_imu ob::openobsdk ob::examples::common)

set_target_properties(ob_imu PROPERTIES FOLDER "Examples")

Expand Down
2 changes: 1 addition & 1 deletion examples/1.stream.infrared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_infrared)
add_executable(ob_infrared infrared.cpp)

set_property(TARGET ob_infrared PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_infrared OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_infrared ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties (ob_infrared PROPERTIES FOLDER "Examples")


Expand Down
3 changes: 1 addition & 2 deletions examples/1.stream.infrared/infrared.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "window.hpp"

#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>

int main(int argc, char **argv) try {
// Create a pipeline with default device.
Expand Down
2 changes: 1 addition & 1 deletion examples/1.stream.multi_streams/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_multi_streams)
add_executable(ob_multi_streams multi_streams.cpp)

set_property(TARGET ob_multi_streams PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_multi_streams OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_multi_streams ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties(ob_multi_streams PROPERTIES FOLDER "Examples")

# ob_install_example_target(ob_multi_streams) ob_install_example_current_source("/cpp/1.stream.multi_streams")
4 changes: 2 additions & 2 deletions examples/1.stream.multi_streams/multi_streams.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "window.hpp"

#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>

#include <mutex>
#include <thread>

Expand Down
2 changes: 1 addition & 1 deletion examples/3.advanced.hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ project(ob_hdr)
add_executable(ob_hdr hdr.cpp)

set_property(TARGET ob_hdr PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_hdr OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_hdr ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties(ob_hdr PROPERTIES FOLDER "Examples")
# ob_install_example_target(ob_hdr) ob_install_example_current_source("/cpp/3.advanced.hdr")
3 changes: 1 addition & 2 deletions examples/3.advanced.hdr/hdr.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "window.hpp"

#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>

int main(int argc, char **argv) try {
// Create a pipeline with default device
Expand Down
2 changes: 1 addition & 1 deletion examples/3.advanced.point_cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_point_cloud)
add_executable(ob_point_cloud point_cloud.cpp)

set_property(TARGET ob_point_cloud PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_point_cloud OrbbecSDK)
target_link_libraries(ob_point_cloud ob::openobsdk ob::examples::common)

set_target_properties(ob_point_cloud PROPERTIES FOLDER "Examples")

Expand Down
4 changes: 2 additions & 2 deletions examples/3.advanced.point_cloud/point_cloud.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "openobsdk/ObSensor.hpp"
// #include "opencv2/opencv.hpp"
#include <openobsdk/ObSensor.h>

#include <fstream>
#include <iostream>
#include "utils.hpp"
Expand Down
2 changes: 1 addition & 1 deletion examples/3.advanced.post_processing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_post_processing)
add_executable(ob_post_processing post_processing.cpp)

set_property(TARGET ob_post_processing PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_post_processing OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_post_processing ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties(ob_post_processing PROPERTIES FOLDER "Examples")

# ob_install_example_target(ob_post_processing) ob_install_example_current_source("/cpp/3.advanced.post_processing")
3 changes: 1 addition & 2 deletions examples/3.advanced.post_processing/post_processing.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "window.hpp"

#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"
#include <openobsdk/ObSensor.h>

int main(int argc, char **argv) try {
// Create a pipeline with default device
Expand Down
2 changes: 1 addition & 1 deletion examples/3.advanced.preset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ob_preset)
add_executable(ob_preset preset.cpp)

set_property(TARGET ob_preset PROPERTY CXX_STANDARD 11)
target_link_libraries(ob_preset OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_preset ob::openobsdk ob::examples::common ${OpenCV_LIBS})
set_target_properties(ob_preset PROPERTIES FOLDER "Examples")

# ob_install_example_target(ob_preset) ob_install_example_current_source("/cpp/3.advanced.preset")
4 changes: 1 addition & 3 deletions examples/3.advanced.preset/preset.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "window.hpp"

#include <iostream>
#include "openobsdk/hpp/Pipeline.hpp"
#include "openobsdk/hpp/Error.hpp"

#include <openobsdk/ObSensor.h>
int main(int argc, char **argv) try {
// Create a pipeline with default device.
ob::Pipeline pipe;
Expand Down
9 changes: 6 additions & 3 deletions examples/c_examples/0.c_quick_start/quick_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void check_ob_error(ob_error **err) {
if(*err) {
const char *error_message = ob_error_get_message(*err);
fprintf(stderr, "Error: %s\n", error_message);
ob_delete_error(*err);
exit(-1);
ob_delete_error(*err);
}
*err = NULL;
}
Expand All @@ -41,8 +41,11 @@ int main(void){

// Main loop
while(true) { // Wait in a loop, and exit after the window receives the "ESC_KEY" key
// Wait for up to 1000ms for a frameset in blocking mode.
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 1000, &error);
if(kbhit() && getch() == ESC) {
break;
}
// Wait for up to 100ms for a frameset in blocking mode.
ob_frame *frameset = ob_pipeline_wait_for_frameset(pipe, 100, &error);
check_ob_error(&error);

if(frameset != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion examples/c_examples/1.c_enumerate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.1.15)
project(ob_enumerate_c)
add_executable(ob_enumerate_c enumerate.c)

target_link_libraries(ob_enumerate_c OrbbecSDK)
target_link_libraries(ob_enumerate_c PRIVATE ob::openobsdk ob::examples::common)

set_target_properties(ob_enumerate_c PROPERTIES FOLDER "Examples_c")
set_target_properties(ob_enumerate_c PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
Expand Down
37 changes: 15 additions & 22 deletions examples/c_examples/1.c_enumerate/enumerate.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#include <stdio.h>
#include <stdlib.h>

#include <openobsdk/h/Error.h>
#include <openobsdk/h/Frame.h>
#include <openobsdk/h/ObTypes.h>
#include <openobsdk/h/Pipeline.h>
#include <openobsdk/h/StreamProfile.h>
#include <openobsdk/h/Device.h>
#include <openobsdk/h/Sensor.h>
#include <openobsdk/h/Context.h>
#include <openobsdk/ObSensor.h>

const char* sensor_types[] = {
"OB_SENSOR_UNKNOWN",
Expand Down Expand Up @@ -53,8 +46,8 @@ const char *rate_types[] = {
void check_ob_error(ob_error **err) {
if(*err) {
const char* error_message = ob_error_get_message(*err);
ob_delete_error(*err);
fprintf(stderr, "Error: %s\n", error_message);
ob_delete_error(*err);
exit(-1);
}
*err = NULL;
Expand All @@ -74,20 +67,20 @@ void enumerate_stream_info(ob_sensor *sensor, ob_error **error){
ob_stream_profile *stream_profile = ob_stream_profile_list_get_profile(stream_profile_list, index, error);
// Print video stream profile information.
if(sensor_type == OB_SENSOR_IR || sensor_type == OB_SENSOR_COLOR || sensor_type == OB_SENSOR_DEPTH || sensor_type == OB_SENSOR_IR_LEFT || sensor_type == OB_SENSOR_IR_RIGHT){
ob_format stream_format = ob_stream_profile_format(stream_profile, error);
uint32_t stream_width = ob_video_stream_profile_width(stream_profile, error);
uint32_t stream_height = ob_video_stream_profile_height(stream_profile, error);
uint32_t stream_fps = ob_video_stream_profile_fps(stream_profile, error);
ob_format stream_format = ob_stream_profile_get_format(stream_profile, error);
uint32_t stream_width = ob_video_stream_profile_get_width(stream_profile, error);
uint32_t stream_height = ob_video_stream_profile_get_height(stream_profile, error);
uint32_t stream_fps = ob_video_stream_profile_get_fps(stream_profile, error);
printf(" - type:%s, width:%d, height:%d, fps:%d\n", stream_types[stream_format], stream_width, stream_height, stream_fps);
}else if(sensor_type == OB_SENSOR_ACCEL){
// Print acc stream profile information.
ob_format stream_format = ob_stream_profile_format(stream_profile, error);
ob_accel_sample_rate acc_fps = ob_accel_stream_profile_sample_rate(stream_profile, error);
ob_format stream_format = ob_stream_profile_get_format(stream_profile, error);
ob_accel_sample_rate acc_fps = ob_accel_stream_profile_get_sample_rate(stream_profile, error);
printf(" - type:%s, fps:%s\n", stream_types[stream_format], rate_types[acc_fps]);
}else if(sensor_type == OB_SENSOR_GYRO){
// Print gyro stream profile information.
ob_format stream_format = ob_stream_profile_format(stream_profile, error);
ob_gyro_sample_rate gyro_fps = ob_gyro_stream_profile_sample_rate(stream_profile, error);
ob_format stream_format = ob_stream_profile_get_format(stream_profile, error);
ob_gyro_sample_rate gyro_fps = ob_gyro_stream_profile_get_sample_rate(stream_profile, error);
printf(" - type:%s, fps:%s\n", stream_types[stream_format], rate_types[gyro_fps]);
}
}
Expand All @@ -99,11 +92,11 @@ void enumerate_device_info(ob_device *device,int index, ob_error **error){
// Get device information.
ob_device_info * dev_inf = ob_device_get_device_info(device, error);
// Get device name.
const char * dev_name = ob_device_info_name(dev_inf, error);
const char *dev_name = ob_device_info_get_name(dev_inf, error);
// Get device pid.
int dev_pid = ob_device_info_pid(dev_inf, error);
int dev_pid = ob_device_info_get_pid(dev_inf, error);
// Get device serial number.
const char * dev_sn = ob_device_info_serial_number(dev_inf, error);
const char * dev_sn = ob_device_info_get_serial_number(dev_inf, error);
printf("%d - device name : %s, device pid : %d, device sn : %s\n",index, dev_name, dev_pid, dev_sn);
}

Expand Down Expand Up @@ -147,7 +140,7 @@ int main(){
ob_device_list *dev_list = ob_query_device_list(ctx, &error);
check_ob_error(&error);
// Get device count from device list.
int dev_count = ob_device_list_device_count(dev_list, &error);
int dev_count = ob_device_list_get_device_count(dev_list, &error);
check_ob_error(&error);
if(dev_count == 0) {
printf("Device not found!\n");
Expand Down Expand Up @@ -179,7 +172,7 @@ int main(){

// destroy context
ob_delete_context(ctx, &error);
check_error(&error);
check_ob_error(&error);

return 0;
}
2 changes: 1 addition & 1 deletion examples/c_examples/2.c_depth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.1.15)
project(ob_depth_c)
add_executable(ob_depth_c depth.c)

target_link_libraries(ob_depth_c OrbbecSDK ${OpenCV_LIBS})
target_link_libraries(ob_depth_c PRIVATE ob::openobsdk ob::examples::common ${OpenCV_LIBS})

set_target_properties(ob_depth_c PROPERTIES FOLDER "Examples_c")
set_target_properties(ob_depth_c PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
Expand Down
23 changes: 9 additions & 14 deletions examples/c_examples/2.c_depth/depth.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#include <stdio.h>
#include <stdlib.h>

#include <openobsdk/h/Error.h>
#include <openobsdk/h/Frame.h>
#include <openobsdk/h/ObTypes.h>
#include <openobsdk/h/Pipeline.h>
#include <openobsdk/h/StreamProfile.h>
#include <openobsdk/h/Device.h>
#include <openobsdk/ObSensor.h>

#include "utils.hpp"
#define ESC 27
Expand All @@ -17,8 +12,8 @@
void check_ob_error(ob_error **err) {
if(*err) {
const char* error_message = ob_error_get_message(*err);
ob_delete_error(*err);
fprintf(stderr, "Error: %s\n", error_message);
ob_delete_error(*err);
exit(-1);
}
*err = NULL;
Expand Down Expand Up @@ -51,25 +46,25 @@ int main(int argc, char **args) {
}

// Get the depth frame from frameset。
ob_frame *depth_frame = ob_frameset_depth_frame(frameset, &error);
ob_frame *depth_frame = ob_frameset_get_depth_frame(frameset, &error);
check_ob_error(&error);
if(depth_frame != NULL) {
// Get index from depth frame.
uint32_t index = ob_frame_index(depth_frame, &error);
uint32_t index = ob_frame_get_index(depth_frame, &error);
check_ob_error(&error);
// Get format from depth frame.
ob_format format = ob_frame_format(depth_frame, &error);
ob_format format = ob_frame_get_format(depth_frame, &error);
check_ob_error(&error);

// for Y16 format depth frame, print the distance of the center pixel every 30 frames
if(index % 30 == 0 && format == OB_FORMAT_Y16) {
uint32_t width = ob_video_frame_width(depth_frame, &error);
uint32_t width = ob_video_frame_get_width(depth_frame, &error);
check_ob_error(&error);
uint32_t height = ob_video_frame_height(depth_frame, &error);
uint32_t height = ob_video_frame_get_height(depth_frame, &error);
check_ob_error(&error);
float scale = ob_depth_frame_get_value_scale(depth_frame, &error);
check_ob_error(&error);
uint16_t *data = (uint16_t *)ob_frame_data(depth_frame, &error);
uint16_t *data = (uint16_t *)ob_frame_get_data(depth_frame, &error);
check_ob_error(&error);

// pixel value multiplied by scale is the actual distance value in millimeters
Expand All @@ -80,7 +75,7 @@ int main(int argc, char **args) {
}
ob_delete_frame(depth_frame, &error);
}
ob_delete_frameset(frameset, &error);
ob_delete_frame(frameset, &error);
check_ob_error(&error);
};

Expand Down
1 change: 1 addition & 0 deletions include/openobsdk/ObSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <openobsdk/h/ObTypes.h>
#include <openobsdk/h/Pipeline.h>
#include <openobsdk/h/Property.h>
//#include <openobsdk/h/RecordPlayback.h>
#include <openobsdk/h/Sensor.h>
#include <openobsdk/h/StreamProfile.h>
#include <openobsdk/h/Version.h>

0 comments on commit 4c704b3

Please sign in to comment.