|
@@ -1030,7 +1030,6 @@ namespace OTSIMGPROC
|
|
|
m_pFieldData->SetParticleList(listParticleEmpty);
|
|
|
|
|
|
|
|
|
- //LogInfoTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: no particle is found."));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1038,13 +1037,11 @@ namespace OTSIMGPROC
|
|
|
|
|
|
|
|
|
// get the area image
|
|
|
- COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
|
|
|
- COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
|
|
|
+
|
|
|
|
|
|
Mat blurImg;
|
|
|
Mat srcImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
|
|
|
- //Mat srcImg=Mat(nWidthImg,;
|
|
|
- //srcImg.data = pPixel;
|
|
|
+
|
|
|
medianBlur(srcImg, blurImg, 3);//smooth the edge
|
|
|
|
|
|
|
|
@@ -1183,7 +1180,7 @@ namespace OTSIMGPROC
|
|
|
|
|
|
Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
|
|
|
Mat blurImg;
|
|
|
- medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
|
|
|
+ medianBlur(cvcopyImg, blurImg, 5);//smooth the edge
|
|
|
|
|
|
vector<vector<Point>>contours;
|
|
|
|
|
@@ -1340,15 +1337,12 @@ namespace OTSIMGPROC
|
|
|
|
|
|
Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
|
|
|
Mat blurImg;
|
|
|
- medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
|
|
|
- /*imshow("blur", blurImg);
|
|
|
- imshow("original", cvcopyImg);*/
|
|
|
+ medianBlur(cvcopyImg, blurImg, 5);//get rid of the noise point.
|
|
|
|
|
|
- //vector<vector<Point>>contours;
|
|
|
- Mat out, stats, centroids;
|
|
|
- int number = connectedComponentsWithStats(blurImg, out, stats, centroids, 8, CV_16U);
|
|
|
+ Mat labels, stats, centroids;
|
|
|
+ int number = connectedComponentsWithStats(blurImg, labels, stats, centroids, 8, CV_16U);
|
|
|
|
|
|
- //findContours(cvcopyImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
|
|
|
+
|
|
|
|
|
|
COTSParticleList listParticleOut;
|
|
|
for (size_t i = 1; i < number; i++)
|
|
@@ -1363,31 +1357,33 @@ namespace OTSIMGPROC
|
|
|
int area = stats.at<int>(i, CC_STAT_AREA);
|
|
|
|
|
|
|
|
|
- //Rect rectMax = boundingRect(contours[i]);
|
|
|
+
|
|
|
Rect rectMax = Rect(x, y, w, h);
|
|
|
- Mat rectROI = blurImg(rectMax).clone();
|
|
|
-
|
|
|
+ Mat rectROI = labels(rectMax).clone();
|
|
|
+ Mat imageROI = blurImg(rectMax).clone();
|
|
|
|
|
|
- //exclude the point which intersect into this bounding box but is not in this contour.
|
|
|
+ //exclude the point which intersect into this bounding box but is not in this group.
|
|
|
+ int curlabel = i;
|
|
|
for (int nX = 0; nX < rectROI.rows; nX++)
|
|
|
{
|
|
|
for (int nY = 0; nY < rectROI.cols; nY++)
|
|
|
{
|
|
|
int v = rectROI.data[nX, nY];
|
|
|
- if (v == i)
|
|
|
+
|
|
|
+ if (v == curlabel)
|
|
|
{
|
|
|
- rectROI.data[nX, nY] = 1;
|
|
|
+ imageROI.data[nX, nY] = 255;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- rectROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
|
|
|
+ imageROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, rectROI.data, listParticleOut);
|
|
|
+ GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, imageROI.data, listParticleOut);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1501,8 +1497,7 @@ namespace OTSIMGPROC
|
|
|
listParticleEmpty.clear();
|
|
|
m_pFieldData->SetParticleList(listParticleEmpty);
|
|
|
|
|
|
-
|
|
|
- //LogInfoTrace(__FILE__, __LINE__, _T("RemoveBSEImageBG: no particle is found."));
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1511,37 +1506,55 @@ namespace OTSIMGPROC
|
|
|
|
|
|
|
|
|
Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
|
|
|
- Mat blurImg;
|
|
|
- medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
|
|
|
+ //Mat blurImg;
|
|
|
+ //medianBlur(cvcopyImg, blurImg, 3);//smooth the edge
|
|
|
+
|
|
|
+
|
|
|
+ Mat labels, stats, centroids;
|
|
|
+ int number = connectedComponentsWithStats(cvcopyImg, labels, stats, centroids, 8, CV_16U);
|
|
|
+
|
|
|
|
|
|
- vector<vector<Point>>contours;
|
|
|
- /* imshow("sss", blurImg);*/
|
|
|
- findContours(blurImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
|
|
|
|
|
|
COTSParticleList listParticleOut;
|
|
|
- for (size_t i = 0; i < contours.size(); i++)
|
|
|
+ for (size_t i = 1; i < number; i++)
|
|
|
{
|
|
|
+ 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);
|
|
|
+ int h = stats.at<int>(i, CC_STAT_HEIGHT);
|
|
|
+ int area = stats.at<int>(i, CC_STAT_AREA);
|
|
|
|
|
|
- Rect rectMax = boundingRect(contours[i]);
|
|
|
- Mat rectROI = cvcopyImg(rectMax).clone();
|
|
|
|
|
|
|
|
|
- //exclude the point which intersect into this bounding box but is not in this contour.
|
|
|
+ Rect rectMax = Rect(x, y, w, h);
|
|
|
+ Mat rectROI = labels(rectMax).clone();
|
|
|
+ Mat imageROI = cvcopyImg(rectMax).clone();
|
|
|
+
|
|
|
+ //exclude the point which intersect into this bounding box but is not in this group.
|
|
|
+ int label = i;
|
|
|
for (int nX = 0; nX < rectROI.rows; nX++)
|
|
|
{
|
|
|
for (int nY = 0; nY < rectROI.cols; nY++)
|
|
|
{
|
|
|
- double localPos = pointPolygonTest(contours[i], Point2f(nX + rectMax.x, nY + rectMax.y), false);
|
|
|
- if (localPos == -1)
|
|
|
+ int v = rectROI.data[nX, nY];
|
|
|
+
|
|
|
+ if (v == label)
|
|
|
{
|
|
|
- rectROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
|
|
|
+ imageROI.data[nX, nY] = 255;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ imageROI.data[nX, nY] = 0;//set the value to 0,so we won't consider it when we find segment and feature in this ROI.
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, rectROI.data, listParticleOut);
|
|
|
+ GetParticles(rectMax.x, rectMax.y, rectMax.width, rectMax.height, imageROI.data, listParticleOut);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1802,6 +1815,11 @@ namespace OTSIMGPROC
|
|
|
}
|
|
|
COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
|
|
|
COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
|
|
|
+ //Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);// use the medianblur method to achieve the same effect as open morphology(errod and dialate).
|
|
|
+ //medianBlur(cvcopyImg, cvcopyImg, 5);
|
|
|
+ //pPixel = cvcopyImg.data;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1861,6 +1879,9 @@ namespace OTSIMGPROC
|
|
|
}
|
|
|
COTSImageProcess::BErode3(pPixel, pTempImg, 5, nHeightImg, nWidthImg);
|
|
|
COTSImageProcess::BDilate3(pTempImg, pPixel, 5, nHeightImg, nWidthImg);
|
|
|
+ /*Mat cvcopyImg = Mat(nHeightImg, nWidthImg, CV_8UC1, pPixel);
|
|
|
+ medianBlur(cvcopyImg, cvcopyImg, 5);
|
|
|
+ pPixel = cvcopyImg.data;*/
|
|
|
}
|
|
|
a_pBinImgOut->SetImageData(pPixel,nWidthImg,nHeightImg);
|
|
|
|