Add samples
This commit is contained in:
		
							parent
							
								
									b81299cfa1
								
							
						
					
					
						commit
						7e8218607c
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,4 +1,5 @@
 | 
				
			|||||||
.DS_Store
 | 
					.DS_Store
 | 
				
			||||||
 | 
					/.vscode/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_build/
 | 
					_build/
 | 
				
			||||||
_install/
 | 
					_install/
 | 
				
			||||||
@ -11,3 +12,4 @@ _output/
 | 
				
			|||||||
/*INFO*
 | 
					/*INFO*
 | 
				
			||||||
/*WARNING*
 | 
					/*WARNING*
 | 
				
			||||||
/*ERROR*
 | 
					/*ERROR*
 | 
				
			||||||
 | 
					/*FATAL*
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Makefile
									
									
									
									
									
								
							@ -11,6 +11,7 @@ help:
 | 
				
			|||||||
	@echo "  make build           build project"
 | 
						@echo "  make build           build project"
 | 
				
			||||||
	@echo "  make test            build test and run"
 | 
						@echo "  make test            build test and run"
 | 
				
			||||||
	@echo "  make install         install project"
 | 
						@echo "  make install         install project"
 | 
				
			||||||
 | 
						@echo "  make samples         build samples"
 | 
				
			||||||
	@echo "  make clean|cleanall  clean generated or useless things"
 | 
						@echo "  make clean|cleanall  clean generated or useless things"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: help
 | 
					.PHONY: help
 | 
				
			||||||
@ -76,6 +77,14 @@ install: build
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
.PHONY: install
 | 
					.PHONY: install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# samples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					samples: install
 | 
				
			||||||
 | 
						@$(call echo,Make $@)
 | 
				
			||||||
 | 
						@$(call cmake_build,./samples/_build)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: samples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# clean
 | 
					# clean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
clean:
 | 
					clean:
 | 
				
			||||||
@ -95,6 +104,7 @@ cleanlog:
 | 
				
			|||||||
	@$(call rm_f,*INFO*)
 | 
						@$(call rm_f,*INFO*)
 | 
				
			||||||
	@$(call rm_f,*WARNING*)
 | 
						@$(call rm_f,*WARNING*)
 | 
				
			||||||
	@$(call rm_f,*ERROR*)
 | 
						@$(call rm_f,*ERROR*)
 | 
				
			||||||
 | 
						@$(call rm_f,*FATAL*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: clean cleanall cleanlog
 | 
					.PHONY: clean cleanall cleanlog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										58
									
								
								samples/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								samples/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					cmake_minimum_required(VERSION 3.0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					project(mynteye_samples VERSION 2.0.0 LANGUAGES C CXX)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					get_filename_component(PRO_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
 | 
				
			||||||
 | 
					set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include(${PRO_DIR}/cmake/DetectCXX11.cmake)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
 | 
				
			||||||
 | 
					set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
 | 
				
			||||||
 | 
					string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
 | 
				
			||||||
 | 
					message(STATUS "C_FLAGS: ${CMAKE_C_FLAGS}")
 | 
				
			||||||
 | 
					message(STATUS "CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# packages
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/third_party/glog/_build)
 | 
				
			||||||
 | 
					find_package(glog REQUIRED)
 | 
				
			||||||
 | 
					message(STATUS "Found glog: ${glog_VERSION}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					LIST(APPEND CMAKE_PREFIX_PATH ${PRO_DIR}/_install/lib/cmake)
 | 
				
			||||||
 | 
					find_package(mynteye REQUIRED)
 | 
				
			||||||
 | 
					message(STATUS "Found mynteye: ${mynteye_VERSION}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					LIST(APPEND CMAKE_MODULE_PATH ${PRO_DIR}/cmake)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# targets
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include(${PRO_DIR}/cmake/Common.cmake)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_output")
 | 
				
			||||||
 | 
					set_outdir(
 | 
				
			||||||
 | 
					  "${OUT_DIR}/lib"
 | 
				
			||||||
 | 
					  "${OUT_DIR}/lib"
 | 
				
			||||||
 | 
					  "${OUT_DIR}/bin"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include_directories(
 | 
				
			||||||
 | 
					  ${PRO_DIR}/src
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## camera
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					add_executable(camera camera.cc)
 | 
				
			||||||
 | 
					target_link_libraries(camera mynteye)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(OS_WIN)
 | 
				
			||||||
 | 
					  target_compile_definitions(camera
 | 
				
			||||||
 | 
					    PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					endif()
 | 
				
			||||||
							
								
								
									
										44
									
								
								samples/camera.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								samples/camera.cc
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					#include <glog/logging.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "mynteye/mynteye.h"
 | 
				
			||||||
 | 
					#include "uvc/uvc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct glog_init {
 | 
				
			||||||
 | 
					  glog_init(int /*argc*/, char *argv[]) {
 | 
				
			||||||
 | 
					    // FLAGS_logtostderr = true;
 | 
				
			||||||
 | 
					    FLAGS_alsologtostderr = true;
 | 
				
			||||||
 | 
					    FLAGS_colorlogtostderr = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FLAGS_log_dir = ".";
 | 
				
			||||||
 | 
					    FLAGS_max_log_size = 1024;
 | 
				
			||||||
 | 
					    FLAGS_stop_logging_if_full_disk = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FLAGS_v = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    google::InitGoogleLogging(argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    VLOG(2) << __func__;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ~glog_init() {
 | 
				
			||||||
 | 
					    VLOG(2) << __func__;
 | 
				
			||||||
 | 
					    google::ShutdownGoogleLogging();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MYNTEYE_USE_NAMESPACE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char *argv[]) {
 | 
				
			||||||
 | 
					  glog_init _(argc, argv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  auto context = uvc::create_context();
 | 
				
			||||||
 | 
					  auto devices = uvc::query_devices(context);
 | 
				
			||||||
 | 
					  LOG_IF(FATAL, devices.size() <= 0) << "No devices :(";
 | 
				
			||||||
 | 
					  for (auto &&device : devices) {
 | 
				
			||||||
 | 
					    auto vid = uvc::get_vendor_id(*device);
 | 
				
			||||||
 | 
					    auto pid = uvc::get_product_id(*device);
 | 
				
			||||||
 | 
					    LOG(INFO) << "vid: " << vid << ", pid: " << pid;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -18,11 +18,13 @@ static void check(const char *call, uvc_error_t status) {
 | 
				
			|||||||
struct context {
 | 
					struct context {
 | 
				
			||||||
  uvc_context_t *ctx;
 | 
					  uvc_context_t *ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  context() : ctx() {
 | 
					  context() : ctx(nullptr) {
 | 
				
			||||||
 | 
					    VLOG(2) << __func__;
 | 
				
			||||||
    CALL_UVC(uvc_init, &ctx, nullptr);
 | 
					    CALL_UVC(uvc_init, &ctx, nullptr);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ~context() {
 | 
					  ~context() {
 | 
				
			||||||
 | 
					    VLOG(2) << __func__;
 | 
				
			||||||
    if (ctx)
 | 
					    if (ctx)
 | 
				
			||||||
      uvc_exit(ctx);
 | 
					      uvc_exit(ctx);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -31,17 +33,14 @@ struct context {
 | 
				
			|||||||
struct device {
 | 
					struct device {
 | 
				
			||||||
  const std::shared_ptr<context> parent;
 | 
					  const std::shared_ptr<context> parent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uvc_device_t *uvcdevice;
 | 
					  uvc_device_t *uvcdevice = nullptr;
 | 
				
			||||||
  uvc_device_handle_t *handle = nullptr;
 | 
					  uvc_device_handle_t *handle = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int vid, pid;
 | 
					  int vid, pid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // uvc_stream_ctrl_t ctrl;
 | 
					 | 
				
			||||||
  // uint8_t unit;
 | 
					 | 
				
			||||||
  // video_channel_callback callback = nullptr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  device(std::shared_ptr<context> parent, uvc_device_t *uvcdevice)
 | 
					  device(std::shared_ptr<context> parent, uvc_device_t *uvcdevice)
 | 
				
			||||||
      : parent(parent), uvcdevice(uvcdevice) {
 | 
					      : parent(parent), uvcdevice(uvcdevice) {
 | 
				
			||||||
 | 
					    VLOG(2) << __func__;
 | 
				
			||||||
    open();
 | 
					    open();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uvc_device_descriptor_t *desc;
 | 
					    uvc_device_descriptor_t *desc;
 | 
				
			||||||
@ -52,6 +51,7 @@ struct device {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ~device() {
 | 
					  ~device() {
 | 
				
			||||||
 | 
					    VLOG(2) << __func__;
 | 
				
			||||||
    if (handle)
 | 
					    if (handle)
 | 
				
			||||||
      uvc_close(handle);
 | 
					      uvc_close(handle);
 | 
				
			||||||
    if (uvcdevice)
 | 
					    if (uvcdevice)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user