Browse Source

optimize the parameter of the AutoRemove_background_OTS method

gsp 1 year ago
parent
commit
95c854e51e
1 changed files with 6 additions and 6 deletions
  1. 6 6
      OTSCPP/OTSImagePro/BaseFunction.cpp

+ 6 - 6
OTSCPP/OTSImagePro/BaseFunction.cpp

@@ -389,7 +389,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 		{
 			//提取暗物体
 			cv::Mat black_t;
-			int min_gray = 1;
+			int min_gray = 0;
 			float segma_b = 1.5;
 			int max_gray = int(a - d * segma_b);
 			max_gray = std::min(max_gray, 255);
@@ -399,7 +399,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			{
 				if (i >= min_gray && i <= max_gray)
 				{
-					lutvalues[i] = i;
+					lutvalues[i] = 255;
 				}
 				else
 				{
@@ -412,7 +412,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			//提取亮物体
 			cv::Mat bright_t;
 			int min_gray_bright = int(a + d * segma_b);
-			int max_gray_bright = 254;
+			int max_gray_bright = 255;
 			min_gray_bright = std::max(min_gray_bright, 120);
 
 			uchar lutvalues1[256];
@@ -420,7 +420,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			{
 				if (i >= min_gray_bright && i <= max_gray_bright)
 				{
-					lutvalues1[i] = i;
+					lutvalues1[i] = 255;
 				}
 				else
 				{
@@ -430,7 +430,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			cv::Mat lutpara1(1, 256, CV_8UC1, lutvalues1);
 			cv::LUT(dst_adapt, lutpara1, bright_t);
 			out_thresh = black_t + bright_t;
-			cv::threshold(out_thresh, out_thresh, 1, 255, cv::ThresholdTypes::THRESH_BINARY);
+			//cv::threshold(out_thresh, out_thresh, 1, 255, cv::ThresholdTypes::THRESH_BINARY);
 		}
 		else
 		{
@@ -456,7 +456,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			// binaryImage二值图像;去除部分扩大区域
 			cv::Mat binaryImage = cv::Mat::zeros(image_Negate.size(), image_Negate.type());
 			//筛选系数
-			int segma = 2;
+			int segma = 4;
 			float filter_gray = (mean0 + std0 / segma);
 			//filter_gray = result_THRESH_TRIANGLE;
 			for (int y = 0; y < extractedImage.rows; ++y) {