From 38b031d68b7ade49120f0da36a3bbd4b70331d70 Mon Sep 17 00:00:00 2001 From: Zhanpeng Yang Date: Tue, 8 Oct 2024 18:14:34 +0800 Subject: [PATCH] backup --- CMakeLists.txt | 4 +- src/main.cpp | 115 ++++++++++++++++++++-------------------- src/spectral_camera.cpp | 31 +++++++---- 3 files changed, 82 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e0e3dc..243b48e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD 20) set(PROJ_NAME "SEMS-data-collection") set(PROJ_VERSION_MAJOR 0) set(PROJ_VERSION_MINOR 0) -set(PROJ_VERSION_PATCH 2.20240927_alpha) +set(PROJ_VERSION_PATCH 3.20241008_alpha) #设置项目名字为HelloWorld project(${PROJ_NAME}) @@ -27,6 +27,7 @@ add_library(SpectralCameraLib "${PROJECT_SOURCE_DIR}/src/spectral_camera.cpp") add_library(DisplayLib "${PROJECT_SOURCE_DIR}/src/display.cpp") add_library(DataPreprocessLib "${PROJECT_SOURCE_DIR}/src/data_preprocess.cpp") add_library(VisibleLightCameraLIB "${PROJECT_SOURCE_DIR}/src/visible_light_camera.cpp") +add_library(UtilsLIB "${PROJECT_SOURCE_DIR}/src/utils.cpp") link_directories (${PROJECT_SOURCE_DIR}/../CompliteEnv/Python37) @@ -46,6 +47,7 @@ target_link_libraries(${PROJ_NAME} PUBLIC DisplayLib) target_link_libraries(${PROJ_NAME} PUBLIC opencv_core490 opencv_highgui490 opencv_imgproc490 opencv_photo490 opencv_imgcodecs490 opencv_video490 opencv_videoio490) target_link_libraries(${PROJ_NAME} PUBLIC DataPreprocessLib) +target_link_libraries(${PROJ_NAME} PUBLIC UtilsLIB) diff --git a/src/main.cpp b/src/main.cpp index 1f7242f..ca5a777 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,13 +14,12 @@ #include #include "visible_light_camera.h" -#include +#include #include - -extern unsigned long long int last_file_time=0; -extern unsigned long long int frame_num=0; +extern unsigned long long int last_file_time = 0; +extern unsigned long long int frame_num = 0; int check_update_file_handle(std::string save_dir, std::ofstream &h_raw_spectal_file, std::ofstream &h_header_file, unsigned long long max_file_size, std::ofstream &h_visible_light_file, bool enable_visible_light_camera) { @@ -34,52 +33,57 @@ int check_update_file_handle(std::string save_dir, std::ofstream &h_raw_spectal_ std::string raw_data_file_name = save_dir + std::to_string(now_t); h_raw_spectal_file.open((raw_data_file_name + std::string(".bin").data()), std::ios::out | std::ios::binary | std::ios::app); h_header_file.open((raw_data_file_name + std::string(".csv").data()), std::ios::out | std::ios::app); - + if (enable_visible_light_camera) { if (h_visible_light_file.is_open()) - { - h_visible_light_file.close(); - } + { + h_visible_light_file.close(); + } h_visible_light_file.open((raw_data_file_name + std::string(".img").data()), std::ios::out | std::ios::binary | std::ios::app); } - unsigned long long int now=(unsigned long long int)now_t; - if (last_file_time!=0){ - float t=(float)(now-last_file_time)/1000; + unsigned long long int now = (unsigned long long int)now_t; + if (last_file_time != 0) + { + float t = (float)(now - last_file_time) / 1000; // std::cout<listDevices(); @@ -103,42 +107,39 @@ int main() visible_light_camera->init(configs["visible_light_camera_configs"]["video_capture_index"].as()); } -std::ofstream h_raw_spectal_file,h_header_file, h_visible_light_file; -check_update_file_handle(save_dir, h_raw_spectal_file, h_header_file, max_file_size, h_visible_light_file, enable_visible_light_camera); + std::ofstream h_raw_spectal_file, h_header_file, h_visible_light_file; + check_update_file_handle(save_dir, h_raw_spectal_file, h_header_file, max_file_size, h_visible_light_file, enable_visible_light_camera); bool flag_run = true; while (flag_run) { - spec_camera->read(); - spec_camera->save(h_raw_spectal_file, h_header_file); - frame_num++; - + spec_camera->save(h_raw_spectal_file, h_header_file); + frame_num++; - display_spectral_image(spec_camera->pFrameBuffer, spec_camera->nWidth, spec_camera->nHeight,"Spectral Image"); - + display_spectral_image(spec_camera->pFrameBuffer, spec_camera->nWidth, spec_camera->nHeight, "Spectral Image"); // 如果启动了可见光相机 - if (enable_visible_light_camera) - { - visible_light_camera->read(); - visible_light_camera->save(h_visible_light_file, h_header_file); - display_img(visible_light_camera->image_frame, "Camera"); - } + if (enable_visible_light_camera) + { + visible_light_camera->read(); + visible_light_camera->save(h_visible_light_file, h_header_file); + display_img(visible_light_camera->image_frame, "Camera"); + } - h_header_file << std::endl; + h_header_file << std::endl; - - if (h_raw_spectal_file.tellp()>max_file_size){ -check_update_file_handle(save_dir, h_raw_spectal_file, h_header_file, max_file_size, h_visible_light_file, enable_visible_light_camera); + if (h_raw_spectal_file.tellp() > max_file_size) + { + check_update_file_handle(save_dir, h_raw_spectal_file, h_header_file, max_file_size, h_visible_light_file, enable_visible_light_camera); } if (_kbhit()) { char key = _getch(); - if ( (key == 27)|(key == 'q')) + if ((key == 27) | (key == 'q')) { - flag_run=false; + flag_run = false; } } } @@ -146,15 +147,15 @@ check_update_file_handle(save_dir, h_raw_spectal_file, h_header_file, max_file_s spec_camera->close(); delete spec_camera; if (h_raw_spectal_file.is_open()) - { - h_raw_spectal_file.close(); - } - if (h_header_file.is_open()) - { - h_header_file.close(); - } - if (h_visible_light_file.is_open()) - { - h_visible_light_file.close(); - } + { + h_raw_spectal_file.close(); + } + if (h_header_file.is_open()) + { + h_header_file.close(); + } + if (h_visible_light_file.is_open()) + { + h_visible_light_file.close(); + } } diff --git a/src/spectral_camera.cpp b/src/spectral_camera.cpp index 1bff6b3..ad17e32 100644 --- a/src/spectral_camera.cpp +++ b/src/spectral_camera.cpp @@ -46,6 +46,20 @@ Error: int SpectralCamera::init(int deviceTypeIndex, double FrameRate, double ExposureTime, int BinningSpatial, int BinningSpectral, bool BinningAverage, long long RingBufferSize) { + + // char szPath[512] = {0}; + // GetModuleFileName(NULL, szPath, sizeof(szPath) - 1); + // std::string exe_dir(szPath); + + // // 这里返回的是exe文件的完整路径,包括文件名,所以下面执行两边,就是先取出exe文件名,再去除exe所在文件夹 + // // 即实现找到exe所在文件夹的上层文件夹的绝对路径 + // size_t lastSlashIndex = exe_dir.find_last_of('\\'); + // std::string autoclick_path = exe_dir.substr(0, lastSlashIndex + 1) + "autoClick.exe"; //+1是为了也包含最后一个反斜杠 + // wchar_t *wstr = new wchar_t[autoclick_path.length() + 1]; + // mbstowcs(wstr, autoclick_path.c_str(), autoclick_path.length() + 1); + + // wprintf(L"Started autoClick.exe in %ls\n", wstr); + HINSTANCE state = ShellExecuteW(NULL, L"open", L"autoClick.exe", NULL, NULL, SW_SHOW); // autoClick.exe以及依赖的msvcp140d.dll,ucrtbased.dll,vcruntime140d.dll在lib文件夹中 wprintf(L"Started autoClick.exe. The state code is %d\n", state); @@ -66,7 +80,7 @@ int SpectralCamera::init(int deviceTypeIndex, double FrameRate, double ExposureT this->ExposureTime, this->BinningSpatial, this->BinningSpectral, - this->BinningAverage,this->RingBufferSize); + this->BinningAverage, this->RingBufferSize); wprintf(L"******************************************************\n"); SI_CHK(SI_Open(this->deviceTypeIndex, &this->deviceHandle)); @@ -123,7 +137,6 @@ Error: return -1; } - int SpectralCamera::stop(void) { SI_CHK(SI_Command(this->deviceHandle, L"Acquisition.Stop")); @@ -136,7 +149,6 @@ Error: return -1; } - int SpectralCamera::start(void) { SI_CHK(SI_Command(this->deviceHandle, L"Acquisition.Start")); @@ -149,9 +161,9 @@ Error: return -1; } -int SpectralCamera::reset_FrameRate( double Value) -{ - SI_CHK(SI_SetFloat(this->deviceHandle, L"Camera.FrameRate", Value)); +int SpectralCamera::reset_FrameRate(double Value) +{ + SI_CHK(SI_SetFloat(this->deviceHandle, L"Camera.FrameRate", Value)); return 0; Error: if (SI_FAILED(nError)) @@ -161,9 +173,9 @@ Error: return -1; } -int SpectralCamera::reset_ExposureTime( double Value) -{ - SI_CHK(SI_SetFloat(this->deviceHandle, L"Camera.ExposureTime", Value)); +int SpectralCamera::reset_ExposureTime(double Value) +{ + SI_CHK(SI_SetFloat(this->deviceHandle, L"Camera.ExposureTime", Value)); return 0; Error: if (SI_FAILED(nError)) @@ -182,7 +194,6 @@ void SpectralCamera::save(std::ofstream &h_raw_spectral_file, std::ofstream &h_h h_header_file << now_t << "," << raw_spectral_file_size << "," << this->nFrameSize; } - int SpectralCamera::read(void) { SI_CHK(SI_Wait(this->deviceHandle, this->pFrameBuffer, &this->nFrameSize, &this->nFrameNumber, 10000));