Browse Source

Merge branch 'OTSRelease3_2' of http://36.129.169.60:30080/gogsadmin/OTS into OTSRelease3_2

cxs 3 days ago
parent
commit
4a82667052

+ 1 - 1
Bin/x64/Debug/Config/SysData/OTSProgMgrParam.pmf

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <XMLData RunMode="ProfessionalMode" SysType="IncA">
-  <Member RegName="BrightnessContrastRegulateParam" AutoRegulateType="EveryPeriod" BrightPhaseElement="Al" BrightPhaseValue="124" DarkPhaseElement="C" DarkPhaseValue="11" InitialBrightness="45.53382111" InitialContrast="60.21995716" mag="100" Period="5" StdMaterialOTSPos="41475,-4357" ToRun="true" />
+  <Member RegName="BrightnessContrastRegulateParam" AutoRegulateType="EveryPeriod" BrightPhaseElement="Al" BrightPhaseValue="124" DarkPhaseElement="C" DarkPhaseValue="11" InitialBrightness="45.53382111" InitialContrast="60.21995716" mag="100" Period="5" StdMaterialOTSPos="41475,-4357" ToRun="false" />
   <Member RegName="GenParam" DefaultArea="1450" DefaultSampleName="Sample" DefaultShape="0" EngineType="1:ExpressionParse" MeasParamFileFolderName=".\Config\ProData\" MeasSwitch="true" PartSTDLibFolderName=".\Config\SysData\" PropertyDisplayMode="0" StdLibFileName="zz" SteelTechnology="0" />
   <Member RegName="ImageProcParam" AutoBGRemoveType="0:MIDDLE" BGRemoveType="1:MANUAL" MatrixStep="0" OverlapParam="0" ParticleSelectionCondition="">
     <Member RegName="BGGray" end="110" start="0" />

+ 18 - 18
Bin/x64/Debug/Config/SysData/OTSStage.stg

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<XMLData Modify="true" PathName=".\Config\SysData\OTSStage.stg" WorkingStageId="6">
+<XMLData Modify="false" PathName=".\Config\SysData\OTSStage.stg" WorkingStageId="4">
   <Collection RegName="Stagelist">
     <Member strName="圆形九圆孔50mm">
       <Member RegName="boundary" PolygonPoint="" rectDomian="0,0,50000,0" shape="0:ROUND" />
@@ -59,23 +59,23 @@
       <Member RegName="std" PolygonPoint="" rectDomian="6300,0,2,0" shape="0:ROUND" />
       <Collection RegName="Holes">
         <Member HoleName="9" rectDomian="0,0,12000,0" shape="0" />
-        <Member HoleName="2" rectDomian="0,25000,12000,0" shape="0" />
-        <Member HoleName="3" rectDomian="-15000,25000,12000,0" shape="0" />
-        <Member HoleName="1" rectDomian="15000,25500,12000,0" shape="0" />
-        <Member HoleName="4" rectDomian="22000,13000,12000,0" shape="0" />
-        <Member HoleName="5" rectDomian="7000,13000,12000,0" shape="0" />
-        <Member HoleName="6" rectDomian="-7500,13000,12000,0" shape="0" />
-        <Member HoleName="7" rectDomian="-22500,13000,12000,0" shape="0" />
-        <Member HoleName="8" rectDomian="14000,0,12000,0" shape="0" />
-        <Member HoleName="10" rectDomian="-15000,0,12000,0" shape="0" />
-        <Member HoleName="11" rectDomian="-30000,0,12000,0" shape="0" />
-        <Member HoleName="12" rectDomian="22000,-12500,12000,0" shape="0" />
-        <Member HoleName="13" rectDomian="7000,-12500,12000,0" shape="0" />
-        <Member HoleName="14" rectDomian="-7500,-12500,12000,0" shape="0" />
-        <Member HoleName="15" rectDomian="-22500,-12500,12000,0" shape="0" />
-        <Member HoleName="16" rectDomian="14500,-24500,12000,0" shape="0" />
-        <Member HoleName="17" rectDomian="-500,-24500,12000,0" shape="0" />
-        <Member HoleName="18" rectDomian="-14500,-24500,12000,0" shape="0" />
+        <Member HoleName="2" rectDomian="-25000,0,12000,0" shape="0" />
+        <Member HoleName="3" rectDomian="-25000,-15000,12000,0" shape="0" />
+        <Member HoleName="1" rectDomian="-25500,15000,12000,0" shape="0" />
+        <Member HoleName="4" rectDomian="-13000,22000,12000,0" shape="0" />
+        <Member HoleName="5" rectDomian="-13000,7000,12000,0" shape="0" />
+        <Member HoleName="6" rectDomian="-13000,-7500,12000,0" shape="0" />
+        <Member HoleName="7" rectDomian="-13000,-22500,12000,0" shape="0" />
+        <Member HoleName="8" rectDomian="0,14000,12000,0" shape="0" />
+        <Member HoleName="10" rectDomian="0,-15000,12000,0" shape="0" />
+        <Member HoleName="11" rectDomian="0,-30000,12000,0" shape="0" />
+        <Member HoleName="12" rectDomian="12500,22000,12000,0" shape="0" />
+        <Member HoleName="13" rectDomian="12500,7000,12000,0" shape="0" />
+        <Member HoleName="14" rectDomian="12500,-7500,12000,0" shape="0" />
+        <Member HoleName="15" rectDomian="12500,-22500,12000,0" shape="0" />
+        <Member HoleName="16" rectDomian="24500,14500,12000,0" shape="0" />
+        <Member HoleName="17" rectDomian="24500,-500,12000,0" shape="0" />
+        <Member HoleName="18" rectDomian="24500,-14500,12000,0" shape="0" />
       </Collection>
     </Member>
     <Member strName="Cleanness三孔样品台">

+ 0 - 1
Bin/x64/Debug/Resources/XMLData/AppResource_ZH.xml

@@ -916,7 +916,6 @@
 	  <Control name="col10" text="特征/夹杂物指数" />
 	  <Control name="col11" text="纳入指数/比例因子" />
 	  <Control name="col12" text="放大倍数" />
-	  <Control name="col20" text="已检测视场面积 (mm²)" />
     </Controls>
  </Form>
   <Form>

+ 49 - 48
OTSCPP/OTSImagePro/BaseFunction.cpp

@@ -12,7 +12,7 @@
 using namespace cv;
 using namespace std;
 using namespace OTSDATA;
-/***** 求两点间距离*****/
+/***** get the distance between two point*****/
 float getDistance(Point pointO, Point pointA)
 {
 	float distance;
@@ -21,16 +21,16 @@ float getDistance(Point pointO, Point pointA)
 	return distance;
 
 }
-/***** 点到直线的距离:P到AB的距离*****/
-//P为线外一点,AB为线段两个端点
+/***** get the distance betweem a point and a line*****/
+//p is the point, A and B are the two points of the line
 float  getDist_P2L(Point pointP, Point pointA, Point pointB)
 {
-	//求直线方程
+	//get the line equation Ax+By+C=0
 	int A = 0, B = 0, C = 0;
 	A = pointA.y - pointB.y;
 	B = pointB.x - pointA.x;
 	C = pointA.x * pointB.y - pointA.y * pointB.x;
-	//代入点到直线距离公式
+	//put the point into the line distance equation
 	float distance = 0;
 	distance = ((float)abs(A * pointP.x + B * pointP.y + C)) / ((float)sqrtf(A * A + B * B));
 	return distance;
@@ -44,27 +44,27 @@ int  Side(Point P1, Point P2, Point point)
 void  FindInnerCircleInContour(vector<Point> contour, Point& center, int& radius)
 {
 	Rect r = boundingRect(contour);
-	int nL = r.x, nR = r.br().x; //轮廓左右边界
-	int nT = r.y, nB = r.br().y; //轮廓上下边界
+	int nL = r.x, nR = r.br().x; //the left and right boundaries of the contour
+	int nT = r.y, nB = r.br().y; //the top and bottom boundaries of the contour
 
 	double dist = 0;
 	double maxdist = 0;
 
-	for (int i = nL; i < nR; i++)  //
+	for (int i = nL; i < nR; i++)  //column
 	{
-		for (int j = nT; j < nB; j++)  //
+		for (int j = nT; j < nB; j++)  //row
 		{
-			//计算轮廓内部各点到最近轮廓点的距离
+			//calculate the distance between the inside point and the contour
 			dist = pointPolygonTest(contour, Point(i, j), true);
 			if (dist > maxdist)
 			{
-				//求最大距离,只有轮廓最中心的点才距离最大
+				//get the point with the maximum distance
 				maxdist = dist;
 				center = Point(i, j);
 			}
 		}
 	}
-	radius = maxdist;  //圆半径
+	radius = maxdist;  //the radius is the maximum distance between the inside point and the contour
 }
 BOOL GetParticleAverageChord(std::vector<Point>  listEdge, double a_PixelSize, double& dPartFTD)
 {
@@ -192,14 +192,15 @@ CBSEImgPtr GetBSEImgFromMat(Mat inImg)
 	return bse;
 }
 /***********************************************************
-增强算法的原理在于先统计每个灰度值在整个图像中所占的比例
-然后以小于当前灰度值的所有灰度值在总像素中所占的比例,作为增益系数
-对每一个像素点进行调整。由于每一个值的增益系数都是小于它的所有值所占
-的比例和。所以就使得经过增强之后的图像亮的更亮,暗的更暗。
+
+the enhancement algorithm is based on the proportion of each gray value in the entire image
+Then, as a gain factor, the proportion of all gray values less than the current gray value in the total pixels
+Each pixel point is adjusted. Since the gain factor of each value is the sum of the proportions of all values less than it.
+So the image after enhancement is brighter and darker.
 ************************************************************/
 void ImageStretchByHistogram(const Mat& src, Mat& dst)
 {
-	//判断传入参数是否正常
+	//judge the size of the two images
 	if (!(src.size().width == dst.size().width))
 	{
 		cout << "error" << endl;
@@ -214,7 +215,7 @@ void ImageStretchByHistogram(const Mat& src, Mat& dst)
 	int width = src.size().width;
 	long wMulh = height * width;
 
-	//统计每一个灰度值在整个图像中所占个数
+	//statistics of each gray value in the image
 	for (int x = 0; x < width; x++)
 	{
 		for (int y = 0; y < height; y++)
@@ -224,13 +225,13 @@ void ImageStretchByHistogram(const Mat& src, Mat& dst)
 		}
 	}
 
-	//使用上一步的统计结果计算每一个灰度值所占总像素的比例
+	//using the number of each gray value to calculate the proportion of each gray value in the total pixels
 	for (int i = 0; i < 256; i++)
 	{
 		p[i] = num[i] / wMulh;
 	}
 
-	//计算每一个灰度值,小于当前灰度值的所有灰度值在总像素中所占的比例
+	//calculate the cumulative distribution function
 	//p1[i]=sum(p[j]);	j<=i;
 	for (int i = 0; i < 256; i++)
 	{
@@ -238,7 +239,7 @@ void ImageStretchByHistogram(const Mat& src, Mat& dst)
 			p1[i] += p[k];
 	}
 
-	//以小于当前灰度值的所有灰度值在总像素中所占的比例,作为增益系数对每一个像素点进行调整。
+	//using the cumulative distribution function to adjust the pixel value
 	for (int y = 0; y < height; y++)
 	{
 		for (int x = 0; x < width; x++) {
@@ -248,13 +249,13 @@ void ImageStretchByHistogram(const Mat& src, Mat& dst)
 	}
 	return;
 }
-//调整图像对比度
+//adjust the contrast of the image
 Mat AdjustContrastY(const Mat& img)
 {
 	Mat out = Mat::zeros(img.size(), CV_8UC1);
 	Mat workImg = img.clone();
 
-	//对图像进行对比度增强
+	//enhance the image
 	ImageStretchByHistogram(workImg, out);
 
 	return Mat(out);
@@ -267,7 +268,7 @@ void CVRemoveBG(const cv::Mat& img, cv::Mat& dst,int bgstart,int bgend/*, long&
 	int max_gray = bgend;
 	if (img.empty())
 	{
-		std::cout << "图像为空";
+		std::cout << "empty image";
 		return;
 	}
 	Mat image = img.clone();
@@ -275,7 +276,7 @@ void CVRemoveBG(const cv::Mat& img, cv::Mat& dst,int bgstart,int bgend/*, long&
 	{
 		cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
 	}
-	//lut 查找表 取规定范围的灰度图 排除拼图时四周灰度为255区域 以及 灰度值较低的区域
+	//lut: lookup table,exclude  the gray value less than min_gray and greater than max_gray
 	uchar lutvalues[256];
 	for (int i = 0; i < 256; i++)
 	{
@@ -292,13 +293,13 @@ void CVRemoveBG(const cv::Mat& img, cv::Mat& dst,int bgstart,int bgend/*, long&
 	cv::Mat lutpara(1, 256, CV_8UC1, lutvalues);
 	cv::LUT(image, lutpara, image);
 	cv::Mat out_fill0, out_fill;
-	//开运算 获得x>5 的元素
+	//open calculation
 	cv::morphologyEx(image, out_fill0, cv::MorphTypes::MORPH_OPEN, cv::getStructuringElement(0, cv::Size(5, 1)), cv::Point(-1, -1), 1);
 	cv::morphologyEx(image, out_fill, cv::MorphTypes::MORPH_OPEN, cv::getStructuringElement(0, cv::Size(1, 5)), cv::Point(-1, -1), 1);
 	out_fill = out_fill + out_fill0;
-	//闭运算 
+	//close calculation
 	cv::morphologyEx(out_fill, out_fill, cv::MorphTypes::MORPH_CLOSE, cv::getStructuringElement(0, cv::Size(3, 3)), cv::Point(-1, -1), 1);
-	//二值
+	//binary thresholding
 	cv::threshold(out_fill, out_fill, 1, 255, cv::ThresholdTypes::THRESH_BINARY);
 	dst = out_fill.clone();
 }
@@ -351,7 +352,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 	auto a = mean[0];
 	auto d = std[0];
 	bool direct_binary = false;
-	if (a > 240)//全亮背景 暗颗粒;直接二值提取 ;特殊情况
+	if (a > 240)//bright background, dark particle;direct binary process ;particular case
 	{
 		direct_binary = true;
 	}
@@ -363,11 +364,11 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 	{
 		both_black_bright = true;
 	}
-	//自适应滤波
+	//adaptive manifold filter
 	cv::Ptr<cv::ximgproc::AdaptiveManifoldFilter> pAdaptiveManifoldFilter
 		= cv::ximgproc::createAMFilter(3.0, 0.1, true);
 	cv::Mat temp1, dst_adapt;
-	cv::Mat out_thresh;//提取前景二值图
+	cv::Mat out_thresh;//get the binary image of the extracted particle
 	if (direct_binary)
 	{
 		int min = 30;
@@ -387,7 +388,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 		cv::Mat image_Negate;
 		if (both_black_bright)
 		{
-			//提取暗物体
+			//get the dark object
 			cv::Mat black_t;
 			int min_gray = 0;
 			float segma_b = 1.5;
@@ -409,7 +410,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			cv::Mat lutpara(1, 256, CV_8UC1, lutvalues);
 			cv::LUT(dst_adapt, lutpara, black_t);
 
-			//提取亮物体
+			//get the bright object
 			cv::Mat bright_t;
 			int min_gray_bright = int(a + d * segma_b);
 			int max_gray_bright = 255;
@@ -434,8 +435,8 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 		}
 		else
 		{
-			//统一将提取物转换为暗物质亮背景
-			if (!direct_binary && (parame0 == 0))//暗物体,暗背景
+			//convert the image to its negative image
+			if (!direct_binary && (parame0 == 0))//dark particle,bright background
 			{
 				image_Negate = image;
 			}
@@ -444,29 +445,29 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 				dst_adapt = ~dst_adapt;
 				image_Negate = ~image;
 			}
-			//三角阈值
+			//triangle thresholding
 			auto result_THRESH_TRIANGLE = cv::threshold(dst_adapt, out_thresh, 100, 255, cv::ThresholdTypes::THRESH_TRIANGLE | img_ThresholdTypes);
 			cv::Mat extractedImage;
 			cv::bitwise_and(image_Negate, image_Negate, extractedImage, out_thresh = out_thresh > 0); // 使用mask > 0将mask转换为二值图像  
-			// 计算提取区域的均值和方差 
+			//calculate the mean and std of the extracted image
 			cv::Scalar mean1, std1;
 			cv::meanStdDev(extractedImage, mean1, std1, out_thresh);
 			auto mean0 = mean1[0];
 			auto std0 = std1[0];
-			// binaryImage二值图像;去除部分扩大区域
+			// binaryImage;remove the pixels greater than the threshold
 			cv::Mat binaryImage = cv::Mat::zeros(image_Negate.size(), image_Negate.type());
-			//筛选系数
+			//the filter coefficient
 			int segma = 4;
 			float filter_gray = (mean0 + std0 / segma);
 			//filter_gray = result_THRESH_TRIANGLE;
 			for (int y = 0; y < extractedImage.rows; ++y) {
 				for (int x = 0; x < extractedImage.cols; ++x) {
 					if (extractedImage.at<uchar>(y, x) >= 1 && extractedImage.at<uchar>(y, x) <= (int)(filter_gray)) {
-						binaryImage.at<uchar>(y, x) = 255; // 设置为白色(255)  
+						binaryImage.at<uchar>(y, x) = 255; //set to white(255)  
 					}
 				}
 			}
-			//直接提取小于parame2(默认为30)的区域
+			//get the less than parame2(default 30)area
 			cv::Mat thing_area;
 			cv::threshold(image_Negate, thing_area, parame2, 255, img_ThresholdTypes);
 			//out_thresh = binaryImage ;
@@ -475,9 +476,9 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 
 	}
 	cv::Mat img_draw = cv::Mat::zeros(image.size(), CV_8UC3);
-	//连通域过滤绘制颗粒
+	//get the connected components
 	
-		//随机颜色
+		//random color
 		cv::RNG rng(10086);
 		cv::Mat labels, stats, controids;
 		int number = cv::connectedComponentsWithStats(out_thresh, labels, stats, controids, 8, CV_16U);
@@ -494,7 +495,7 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			}
 			draw_indexs.push_back(i);
 		}
-		//染色 过滤
+		//color the connected components
 		int w = img_draw.cols;
 		int h = img_draw.rows;
 		cv::Vec3b color = cv::Vec3b(0, 0, 255);
@@ -516,14 +517,14 @@ void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing
 			}
 		}
 	
-	//原图染色
+		//color the particle on the original image
 	//cv::Mat img_blend;
-	//double alpha = 0.7; // 设定img1的权重
-	//double beta = 1 - alpha; // 计算img2的权重
+	//double alpha = 0.7; // set the weight of img1
+	//double beta = 1 - alpha; // calculate the weight of img2
 	//cv::cvtColor(image, image, cv::COLOR_GRAY2BGR);
 	//cv::addWeighted(image, alpha, img_draw, beta, 0.0, img_blend);
 	//dst = img_blend.clone();
-	//二值图
+	//binary image
 	vector<cv::Mat> outs;
 	cv::split(img_draw, outs);
 	dst = outs[2].clone();

+ 4 - 4
OTSCPP/OTSImagePro/BaseFunction.h

@@ -36,9 +36,9 @@ void RemoveBG_old(const cv::Mat& img, cv::Mat& dst, int nBGStart, int nBGEnd, lo
 /// <summary>
 /// 
 /// </summary>
-/// <param name="img">原图</param>
-/// <param name="dst">目标图</param>
+/// <param name="img">original image</param>
+/// <param name="dst">destination image</param>
 /// <param name="black_thing">0 black ;1 bright;2 both black and bright </param>
-/// <param name="min_size">物体最小大小</param>
-/// <param name="min_gray">物体的灰度最大值</param>
+/// <param name="min_size">minimum size</param>
+/// <param name="min_gray">maximum size</param>
 void AutoRemove_background_OTS(const cv::Mat& img, cv::Mat& dst, int black_thing=2, int min_size=1, int min_gray=30);

+ 22 - 22
OTSCPP/OTSImagePro/FieldMgr.cpp

@@ -19,22 +19,22 @@ namespace OTSIMGPROC {
 			{
 				i = 0;
 				j = 0;
-				for (i += c, j += c; j < n - c; j++)//从左到右
+				for (i += c, j += c; j < n - c; j++)//from left to right
 				{
 					if (ou > z) break;
 					arrays[i][j] = ou--;
 				}
-				for (j--, i++; i < n - c; i++) // 从上到下
+				for (j--, i++; i < n - c; i++) //from top to bottom
 				{
 					if (ou > z) break;
 					arrays[i][j] = ou--;
 				}
-				for (i--, j--; j >= c; j--)//从右到左
+				for (i--, j--; j >= c; j--)//from right to left
 				{
 					if (ou > z) break;
 					arrays[i][j] = ou--;
 				}
-				for (j++, i--; i >= c + 1; i--)//从下到上
+				for (j++, i--; i >= c + 1; i--)//from bottom to top
 				{
 					if (ou > z) break;
 					arrays[i][j] = ou--;
@@ -280,12 +280,12 @@ namespace OTSIMGPROC {
 		// start mode
 		OTS_GET_IMAGE_MODE nStartMode = (OTS_GET_IMAGE_MODE)m_fieldStartMode;
 		rectMeasureDomain.NormalizeRect();
-		int height = (ceil((double)rectMeasureDomain.Height()));
-		int width = (ceil((double)rectMeasureDomain.Width()));
+		int height = (double)rectMeasureDomain.Height();
+		int width = (double)rectMeasureDomain.Width();
 		
 			// calculate total columns, rows and make sure the domain area be covered
-			int nTotalCols = (int)(width/ effectiveWidth);
-			int nTotalRows = (int)(height / effectiveHeight);
+		int nTotalCols = ceil((width / effectiveWidth));
+			int nTotalRows = ceil(height / effectiveHeight);
 
 			// calculate column on the left of the centre point
 			int nLeftCols = nTotalCols / 2;
@@ -336,7 +336,7 @@ namespace OTSIMGPROC {
 						mapCenterPoint[sequenceNum] = p;// sorting all the field center point by the sequence number.
 					}
 				}
-				// 判断当前样品获取帧图信息的测量区域为多边形
+				// judge if the measure area is polygon
 				if (m_pMeasureArea->GetShape() == DOMAIN_SHAPE::POLYGON)
 				{
 					std::vector<CPoint> ptPolygon = m_pMeasureArea->GetPolygonPoint();
@@ -367,7 +367,7 @@ namespace OTSIMGPROC {
 	}
 	BOOL CFieldMgr::IsThisPointInMeasureArea(CPoint a_position)
 	{
-		// 判断当前样品获取帧图信息的测量区域为多边形
+		// judge if the measure area is polygon 
 		if (m_pMeasureArea->GetShape() == DOMAIN_SHAPE::POLYGON)
 		{
 			std::vector<CPoint> ptPolygon = m_pMeasureArea->GetPolygonPoint();
@@ -429,25 +429,25 @@ namespace OTSIMGPROC {
 		CRect rectFiled(a_poiField, a_sizeImageSize);
 
 
-		//		// on the top left side, need to test the bottom right  corner
+				// on the top left side, need to test the bottom right  corner
 				if (PtInPolygon(CPoint(rectFiled.right, rectFiled.top), ptPolygon))
 				{
 					return TRUE;
 				}
 
-		//		// on the bottom left side, need to test the top right corner
+				// on the bottom left side, need to test the top right corner
 				if (PtInPolygon(rectFiled.BottomRight(), ptPolygon))
 				{
 					return TRUE;
 				}
 
-		//		// on the top left side, need to test the bottom right  corner
+				// on the top left side, need to test the bottom right  corner
 				if (PtInPolygon(rectFiled.TopLeft(), ptPolygon))
 				{
 					return TRUE;
 				}
 	
-		//		// on the bottom left side, need to test the top right corner
+				// on the bottom left side, need to test the top right corner
 				if (PtInPolygon(CPoint(rectFiled.left, rectFiled.bottom), ptPolygon))
 				{
 					return TRUE;
@@ -458,17 +458,17 @@ namespace OTSIMGPROC {
 	}
 
 
-	//作用:判断点是否在多边形内
-	//p指目标点, ptPolygon指多边形的点集合, nCount指多边形的边数
+	//function:judge whether the point p is in the polygon ptPolygon
+	//p is the particular point, ptPolygon is the collection of the vertex point
 	BOOL CFieldMgr::PtInPolygon(CPoint p, std::vector<CPoint> ptPolygon)
 	{
 		int nCount = ptPolygon.size();
-		// 交点个数  
+		// the polygon must have at least 3 points
 		int nCross = 0;
 		for (int i = 0; i < nCount; i++)
 		{
 			CPoint p1 = ptPolygon[i];
-			CPoint p2 = ptPolygon[(i + 1) % nCount];// 点P1与P2形成连线  
+			CPoint p2 = ptPolygon[(i + 1) % nCount];// the line between the point p1 and p2
 
 			if (p1.y == p2.y)
 				continue;
@@ -476,16 +476,16 @@ namespace OTSIMGPROC {
 				continue;
 			if (p.y >= max(p1.y, p2.y))
 				continue;
-			// 求交点的x坐标(由直线两点式方程转化而来
+			// get the cross point (from the two point equation
 			double x = (double)(p.y - p1.y) * (double)(p2.x - p1.x) / (double)(p2.y - p1.y) + p1.x;
-			// 只统计p1p2与p向右射线的交点  
+			//only count the cross point which is on the right side of the point p 
 			if (x > p.x)
 			{
 				nCross++;
 			}
 		}
-		// 交点为偶数,点在多边形之外  
-		// 交点为奇数,点在多边形之内
+		// the cross point number is even then the point is outside the polygon
+		//the cross point number is odd then the point is inside the polygon
 		if ((nCross % 2) == 1)
 		{
 			//true;

+ 5 - 5
OTSCPP/OTSImagePro/OTSImageProcess.cpp

@@ -132,7 +132,7 @@ namespace OTSIMGPROC
 			{
 				int center_x = centroids.at<double>(i, 0);
 				  int center_y = centroids.at<double>(i, 1);
-				  //���α߿�
+				 
 				  int x = stats.at<int>(i, CC_STAT_LEFT);
 				  int y = stats.at<int>(i, CC_STAT_TOP);
 				  int w = stats.at<int>(i, CC_STAT_WIDTH);
@@ -320,7 +320,7 @@ namespace OTSIMGPROC
 			{
 				int center_x = centroids.at<double>(i, 0);
 				int center_y = centroids.at<double>(i, 1);
-				//���α߿�
+				
 				int x = stats.at<int>(i, CC_STAT_LEFT);
 				int y = stats.at<int>(i, CC_STAT_TOP);
 				int w = stats.at<int>(i, CC_STAT_WIDTH);
@@ -567,7 +567,7 @@ namespace OTSIMGPROC
 		Mat imageGray3;
 
 	
-		cv::cvtColor(matImg, imageGray3, cv::COLOR_GRAY2RGB);//�Ҷ�ת�� opencv4
+		cv::cvtColor(matImg, imageGray3, cv::COLOR_GRAY2RGB);// opencv4
 		cv::watershed(imageGray3, marks);
 
 
@@ -1386,7 +1386,7 @@ namespace OTSIMGPROC
 	void  COTSImageProcess::findPeakAndValley(const vector<int>& v, vector<int>& peakPositions, vector<int>& valleyPositions)
 	{
 		vector<int> diff_v(v.size() - 1, 0);
-		// ����V��һ�ײ�ֺͷ��ź���trend
+	
 		for (vector<int>::size_type i = 0; i != diff_v.size(); i++)
 		{
 			if (v[i + 1] - v[i] > 0)
@@ -1396,7 +1396,7 @@ namespace OTSIMGPROC
 			else
 				diff_v[i] = 0;
 		}
-		// ��Trend����һ������
+		
 		for (int i = diff_v.size() - 1; i >= 0; i--)
 		{
 			if (diff_v[i] == 0 && i == diff_v.size() - 1)

+ 1 - 6
OTSCPP/OTSImagePro/OTSImageProcessParam.cpp

@@ -82,12 +82,7 @@ namespace OTSIMGPROC
 
 	void COTSImageProcessParam::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
 	{
-		/*xmls::xBool xbShowAreaUp;
-		xmls::xBool xbShowAreaDown;
-		xmls::xBool xbShowBGGrayUp;
-		xmls::xBool xbShowBGGrayDown;
-		xmls::xBool xbShowParticleGrayUp;
-		xmls::xBool xbShowParticleGrayDown;*/
+	
 		xmls::Slo slo;
 		slo.Register("IncArea", &m_oIncArea);
 	

+ 19 - 19
OTSIncAMeasureApp/0-OTSModel/OTSDataType/COTSField.cs

@@ -236,6 +236,23 @@ namespace OTSDataType
                     GetPartsBySpecialGray(range, diaRange, pixelsize, grayRange.ifCollectXray);
                 }
             }
+            List<COTSParticleClr> m_listInnerParticles= new List<COTSParticleClr>();
+            for(var i = 0; i < m_listAllParticles.Count; i++)
+            {
+                var part = m_listAllParticles[i];
+                int l = 0, r = 0, t = 0, b = 0;
+                part.GetOTSRect(ref l, ref t, ref r, ref b);
+                COTSRect otsrec = new COTSRect(l, t, r, b);
+                PointF p1 = otsrec.GetCenterPoint();
+                if (m_sample.IsThisPointInMeasureArea(new Point((int)p1.X, (int)p1.Y)))
+                {
+                    m_listInnerParticles.Add(m_listAllParticles[i]);
+                }
+            }
+           
+            m_listAllParticles=m_listInnerParticles;
+
+
             log.Info("Find all particle num:" + GetAllParticles().Count);
 
             return;
@@ -250,6 +267,7 @@ namespace OTSDataType
             imghandler.RemoveBGAndGetParts(this, a_pImageProcessParam, ref allParts);
 
             m_listAllParticles = allParts;
+
             return;
         }
         class particleCompOnArea : IComparer<COTSParticleClr>
@@ -275,17 +293,7 @@ namespace OTSDataType
                 
                 for (var i = 0; i < pXRayParam.GetXrayLimit(); i++)
                 {
-                    var part = m_listAllParticles[i];
-                    int l=0, r=0, t=0, b=0;
-                    part.GetOTSRect(ref l, ref t,ref r, ref b);
-                    COTSRect otsrec = new COTSRect(l, t, r, b);
-                    PointF p1 = otsrec.GetCenterPoint();
-
-                    if (m_sample.IsThisPointInMeasureArea(new Point((int)p1.X, (int)p1.Y)))
-                    {
-                        listXray1.Add(m_listAllParticles[i]);
-                    }
-                   
+                        listXray1.Add(m_listAllParticles[i]);                  
                 }
 
             }
@@ -293,15 +301,7 @@ namespace OTSDataType
             {
                 foreach (var p in m_listAllParticles)
                 {
-                    var part = p;
-                    int l = 0, r = 0, t = 0, b = 0;
-                    part.GetOTSRect(ref l, ref t, ref r, ref b);
-                    COTSRect otsrec = new COTSRect(l, t, r, b);
-                    PointF p1 = otsrec.GetCenterPoint();
-                    if (m_sample.IsThisPointInMeasureArea(new Point((int)p1.X, (int)p1.Y)))
-                    {
                         listXray1.Add(p);
-                    }
                 }
                
             }