From 0203ab4af7b9169f226304977facf7badcd09503 Mon Sep 17 00:00:00 2001 From: gfuse Date: Wed, 15 Sep 2021 18:33:36 +0200 Subject: [PATCH] solve segemtation crash --- GPU_version/vio/depth_filter_log.txt | 0 GPU_version/vio/frame_handler_log.txt | 0 GPU_version/vio/include/vio/cl_class.h | 5 +++++ GPU_version/vio/include/vio/global.h | 9 ++++----- GPU_version/vio/src/depth_filter.cpp | 2 ++ GPU_version/vio/src/feature_detection.cpp | 2 +- GPU_version/vio/src/frame.cpp | 2 +- GPU_version/vio/src/frame_handler_base.cpp | 9 ++------- GPU_version/vio/src/frame_handler_mono.cpp | 2 ++ GPU_version/vio/src/initialization.cpp | 4 +++- GPU_version/vio/src/reprojector.cpp | 2 ++ 11 files changed, 22 insertions(+), 15 deletions(-) create mode 100755 GPU_version/vio/depth_filter_log.txt create mode 100755 GPU_version/vio/frame_handler_log.txt diff --git a/GPU_version/vio/depth_filter_log.txt b/GPU_version/vio/depth_filter_log.txt new file mode 100755 index 0000000..e69de29 diff --git a/GPU_version/vio/frame_handler_log.txt b/GPU_version/vio/frame_handler_log.txt new file mode 100755 index 0000000..e69de29 diff --git a/GPU_version/vio/include/vio/cl_class.h b/GPU_version/vio/include/vio/cl_class.h index 2660fb5..285dccf 100644 --- a/GPU_version/vio/include/vio/cl_class.h +++ b/GPU_version/vio/include/vio/cl_class.h @@ -25,6 +25,7 @@ public: }; template int32_t write(size_t id/*buffer ID*/,T* buf,cl::CommandQueue* queue,cl::Context* context,size_t buf_size){ + assert(buf); cl_int error; _buffers.push_back(std::pair,size_t>(std::pair(cl::Buffer(*context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR , sizeof(T) * buf_size,buf,&error), @@ -36,6 +37,7 @@ public: }; int32_t write(size_t id/*buffer ID*/,cv::Mat& buf,cl::Context* context){ + assert(!buf.empty()); cl_int error; _images.push_back(std::pair(cl::Image2D(*context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, cl::ImageFormat(CL_R, CL_UNSIGNED_INT8), @@ -51,6 +53,7 @@ public: template int32_t reload(size_t id,T* buf,cl::CommandQueue* queue){ + assert(buf); cl_int error; for(auto&& i:_buffers)if(i.second==id){ cl::Event event; @@ -65,6 +68,7 @@ public: return error; }; int32_t reload(size_t id,cv::Mat& buf,cl::Context* context){ + assert(!buf.empty()); cl_int error; try{ for(auto&& i:_images)if(i.second==id){ @@ -161,6 +165,7 @@ public: } template void read(size_t id1/*kernal ID*/,size_t id2/*buffer ID*/,size_t size/*size*/, T* out){ + assert(out); cl_int error; cl::Event event; T* Map_buf=(T*)queue->enqueueMapBuffer(_kernels.at(id1).read(id2).first,CL_NON_BLOCKING,CL_MAP_READ,0,sizeof(T) * size,NULL,&event,&error); diff --git a/GPU_version/vio/include/vio/global.h b/GPU_version/vio/include/vio/global.h index eac3eaf..bbf394f 100644 --- a/GPU_version/vio/include/vio/global.h +++ b/GPU_version/vio/include/vio/global.h @@ -36,11 +36,8 @@ EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Vector3d) EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Vector2d) #endif #include -#define SVO_DEBUG_STREAM(x) ROS_DEBUG_STREAM(x) -#define SVO_INFO_STREAM(x) ROS_INFO_STREAM(x) -#define SVO_WARN_STREAM(x) ROS_WARN_STREAM(x) -#define SVO_WARN_STREAM_THROTTLE(rate, x) ROS_WARN_STREAM_THROTTLE(rate, x) -#define SVO_ERROR_STREAM(x) ROS_ERROR_STREAM(x) +#include +#include namespace vio @@ -51,6 +48,8 @@ namespace vio const double EPS = 0.0000000001; const double PI = 3.14159265; + + static boost::mutex feature_detection_mut_; static std::string time_in_HH_MM_SS_MMM() { using namespace std::chrono; diff --git a/GPU_version/vio/src/depth_filter.cpp b/GPU_version/vio/src/depth_filter.cpp index 9978b93..8cc0f40 100644 --- a/GPU_version/vio/src/depth_filter.cpp +++ b/GPU_version/vio/src/depth_filter.cpp @@ -148,9 +148,11 @@ namespace vio { fprintf(log_,"[%s] init seeds\n",vio::time_in_HH_MM_SS_MMM().c_str()); #endif feature_detector_->setExistingFeatures(frame->fts_); + feature_detection_mut_.lock(); feature_detector_->detect(frame, frame->img_pyr_, Config::triangMinCornerScore(), new_features); + feature_detection_mut_.unlock(); // initialize a seed for every new feature seeds_updating_halt_ = true; seeds_mut_.lock(); diff --git a/GPU_version/vio/src/feature_detection.cpp b/GPU_version/vio/src/feature_detection.cpp index c9dad10..28caf12 100644 --- a/GPU_version/vio/src/feature_detection.cpp +++ b/GPU_version/vio/src/feature_detection.cpp @@ -89,7 +89,7 @@ void FastDetector::detect( gpu_fast_->run(0,img.cols,img.rows); int count[1]={0}; gpu_fast_->read(0,2,1,count); - cl_int2 fast_corners[350000]; + cl_int2 fast_corners[350000]={0}; gpu_fast_->read(0,1,count[0],fast_corners); for(uint i=0;i(std::min(num_obs_last_, Config::maxFts())) - num_observations; if(feature_drop > Config::qualityMaxFtsDrop()) { - SVO_WARN_STREAM("Lost "<< feature_drop <<" features!"); + //SVO_WARN_STREAM("Lost "<< feature_drop <<" features!"); tracking_quality_ = TRACKING_INSUFFICIENT; } } diff --git a/GPU_version/vio/src/frame_handler_mono.cpp b/GPU_version/vio/src/frame_handler_mono.cpp index 67e8c16..e811d7c 100644 --- a/GPU_version/vio/src/frame_handler_mono.cpp +++ b/GPU_version/vio/src/frame_handler_mono.cpp @@ -181,7 +181,9 @@ FrameHandlerBase::UpdateResult FrameHandlerMono::processFrame() new_frame_->Cov_ = init_f.first; // sparse image align SparseImgAlignGpu img_align(Config::kltMaxLevel(), Config::kltMinLevel(),30, SparseImgAlignGpu::GaussNewton, false,gpu_fast_); + feature_detection_mut_.lock(); size_t err=img_align.run(last_frame_, new_frame_, log_); + feature_detection_mut_.unlock(); if(err==-1){ #if VIO_DEBUG fprintf(log_,"[%s] Image Alignment failed -1\n",vio::time_in_HH_MM_SS_MMM().c_str()); diff --git a/GPU_version/vio/src/initialization.cpp b/GPU_version/vio/src/initialization.cpp index af10ef4..2abe4fd 100644 --- a/GPU_version/vio/src/initialization.cpp +++ b/GPU_version/vio/src/initialization.cpp @@ -31,7 +31,7 @@ InitResult KltHomographyInit::addFirstFrame(FramePtr frame_ref) detectFeatures(frame_ref, px_ref_, px_level, f_ref_, gpu_fast_); if(px_ref_.size() < 100) { - SVO_WARN_STREAM_THROTTLE(2.0, "First image has less than 100 features. Retry in more textured environment."); +// SVO_WARN_STREAM_THROTTLE(2.0, "First image has less than 100 features. Retry in more textured environment."); return FAILURE; } #if VIO_DEBUG @@ -126,9 +126,11 @@ void detectFeatures( opencl* gpu_fast) { Features new_features; + feature_detection_mut_.lock(); feature_detection::FastDetector detector( frame->img().cols, frame->img().rows, Config::gridSize(), gpu_fast,Config::nPyrLevels()); detector.detect(frame, frame->img_pyr_, Config::triangMinCornerScore(), new_features); + feature_detection_mut_.unlock(); // now for all maximum corners, initialize a new seed px_vec.clear(); f_vec.clear(); diff --git a/GPU_version/vio/src/reprojector.cpp b/GPU_version/vio/src/reprojector.cpp index 3f1b412..428bcb1 100644 --- a/GPU_version/vio/src/reprojector.cpp +++ b/GPU_version/vio/src/reprojector.cpp @@ -76,9 +76,11 @@ namespace vio { Features keypoints_cur; cv::Ptr extractor = cv::xfeatures2d::FREAK::create(true, true, 22.0f, 4); cv::Ptr matcher = cv::BFMatcher::create(cv::NORM_HAMMING, true); + feature_detection_mut_.lock(); feature_detection::FastDetector detector( frame->img().cols, frame->img().rows, Config::gridSize(), gpu_fast_,Config::nPyrLevels()); detector.detect(frame, frame->img_pyr_, Config::triangMinCornerScore(), keypoints_cur,&descriptors_cur); + feature_detection_mut_.unlock(); list > close_kfs; map_.getCloseKeyframes(frame, close_kfs); if (!last_frame->fts_.empty())