Browse Source

optimize the CVRemoveBG method.

gsp 1 year ago
parent
commit
c87e1928be

+ 7 - 7
OTSCPP/OTSImagePro/BaseFunction.cpp

@@ -261,7 +261,7 @@ Mat AdjustContrastY(const Mat& img)
 }
 
 
-void CVRemoveBG(const cv::Mat& img, cv::Mat& dst,int bgstart,int bgend, long& nNumParticle)
+void CVRemoveBG(const cv::Mat& img, cv::Mat& dst,int bgstart,int bgend/*, long& nNumParticle*/)
 {
 	int min_gray = bgstart;
 	int max_gray = bgend;
@@ -279,10 +279,10 @@ void CVRemoveBG(const cv::Mat& img, cv::Mat& dst,int bgstart,int bgend, long& nN
 	uchar lutvalues[256];
 	for (int i = 0; i < 256; i++)
 	{
-		if (i < min_gray || i > max_gray)
+		if (i <= min_gray || i >= max_gray)
 		{
-			lutvalues[i] = i;
-			nNumParticle++;
+			lutvalues[i] = 255;
+			/*nNumParticle++;*/
 		}
 		else
 		{
@@ -380,9 +380,9 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 	}
 	else
 	{
-		/*cv::GaussianBlur(image, temp1, cv::Size(3, 3), 1.0, 1.0);
-		pAdaptiveManifoldFilter->filter(temp1, dst_adapt, image);*/
-		dst_adapt = image;
+		cv::GaussianBlur(image, temp1, cv::Size(3, 3), 1.0, 1.0);
+		pAdaptiveManifoldFilter->filter(temp1, dst_adapt, image);
+		//dst_adapt = image;
 		cv::ThresholdTypes img_ThresholdTypes = cv::ThresholdTypes::THRESH_BINARY_INV;
 		cv::Mat image_Negate;
 		if (both_black_bright)

+ 1 - 1
OTSCPP/OTSImagePro/BaseFunction.h

@@ -30,7 +30,7 @@ void ImageStretchByHistogram(const Mat& src, Mat& dst);
 
 Mat AdjustContrastY(const Mat& img);
 
-void CVRemoveBG(const cv::Mat& img, cv::Mat& dst, int bgstart, int bgend, long& nNumParticle);
+void CVRemoveBG(const cv::Mat& img, cv::Mat& dst, int bgstart, int bgend/*, long& nNumParticle*/);
 
 void RemoveBG_old(const cv::Mat& img, cv::Mat& dst, int nBGStart, int nBGEnd, long& nNumParticle);
 /// <summary>

+ 2 - 2
OTSCPP/OTSImagePro/OTSImageProcess.cpp

@@ -590,7 +590,7 @@ namespace OTSIMGPROC
 		long nBGEnd;
 		long nPartStart;
 		long nPartEnd;
-		long nNumParticle = 0;
+		//long nNumParticle = 0;
 		if (a_pImageProcessParam->GetBGRemoveType() == OTS_BGREMOVE_TYPE::MANUAL)
 		{
 			nBGStart = a_pImageProcessParam->GetBGGray().GetStart();
@@ -601,7 +601,7 @@ namespace OTSIMGPROC
 			
 			
 			
-			CVRemoveBG(srcImgMat, rstMat, nBGStart, nBGEnd,nNumParticle);
+			CVRemoveBG(srcImgMat, rstMat, nBGStart, nBGEnd);
 			//RemoveBG_old(srcImgMat, rstMat, nBGStart, nBGEnd, nNumParticle);
 
 			pPixel = rstMat.data;

+ 2 - 2
OTSIncAMeasureApp/1-OTSMeasure/Measure/3-MeasureFlow/CSmplMeasure.cs

@@ -44,8 +44,8 @@ namespace OTSModelSharp
       
         protected Queue<COTSField> fieldQueue=new Queue<COTSField>();
       
-        protected IClassifyEngine m_classifyEngine;
-       
+        protected IClassifyEngine m_classifyEngine; 
+
 
         public CSmplMeasure( string a_strWorkingFolder, COTSSample a_pSample)
         {