|
@@ -581,8 +581,9 @@ namespace OTSIMGPROC
|
|
|
BYTE* pSrcImg = a_pImgIn->GetImageDataPointer();
|
|
|
|
|
|
|
|
|
- BYTE* pPixel = new byte[nImgSize];
|
|
|
-
|
|
|
+ BYTE* pPixel= new BYTE[nImgSize];
|
|
|
+ Mat srcImgMat = GetMatDataFromBseImg(a_pImgIn);
|
|
|
+ Mat rstMat;
|
|
|
|
|
|
|
|
|
long nBGStart;
|
|
@@ -597,31 +598,13 @@ namespace OTSIMGPROC
|
|
|
nPartStart = a_pImageProcessParam->GetParticleGray().GetStart();
|
|
|
nPartEnd = a_pImageProcessParam->GetParticleGray().GetEnd();
|
|
|
|
|
|
- // delete background
|
|
|
- for (unsigned int i = 0; i < nImgSize; i++)
|
|
|
- {
|
|
|
- if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
|
|
|
- {
|
|
|
- pPixel[i] = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pPixel[i] = 255;
|
|
|
- nNumParticle++;
|
|
|
- }
|
|
|
- if (pSrcImg[i]<nPartStart || pSrcImg[i]>nPartEnd)
|
|
|
- {
|
|
|
- pPixel[i] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- int errodDilateParam =5;
|
|
|
- if (errodDilateParam > 0)
|
|
|
- {
|
|
|
-
|
|
|
- BErode3(pPixel, pTempImg, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
- BDilate3(pTempImg, pPixel, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ CVRemoveBG(srcImgMat, rstMat, nBGStart, nBGEnd,nNumParticle);
|
|
|
+ //RemoveBG_old(srcImgMat, rstMat, nBGStart, nBGEnd, nNumParticle);
|
|
|
+
|
|
|
+ pPixel = rstMat.data;
|
|
|
|
|
|
|
|
|
|
|
@@ -638,56 +621,25 @@ namespace OTSIMGPROC
|
|
|
switch (a_pImageProcessParam->GetAutoBGRemoveType())
|
|
|
{
|
|
|
case OTS_AUTOBGREMOVE_TYPE::DOWNWARD:
|
|
|
- for (unsigned int i = 0; i < nImgSize; i++)
|
|
|
- {
|
|
|
- if (pSrcImg[i] <= nBGEnd)
|
|
|
- {
|
|
|
- pPixel[i] = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pPixel[i] = 255;
|
|
|
- nNumParticle++;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ //RemoveBG_old(srcImgMat, rstMat, 0, nBGEnd, nNumParticle);
|
|
|
+ CVRemoveBG(srcImgMat, rstMat, 0, nBGEnd, nNumParticle);
|
|
|
break;
|
|
|
case OTS_AUTOBGREMOVE_TYPE::UPWARD:
|
|
|
- for (unsigned int i = 0; i < nImgSize; i++)
|
|
|
- {
|
|
|
- if (pSrcImg[i] >= nBGStart)
|
|
|
- {
|
|
|
- pPixel[i] = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pPixel[i] = 255;
|
|
|
- nNumParticle++;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ //RemoveBG_old(srcImgMat, rstMat, nBGStart, 255, nNumParticle);
|
|
|
+ CVRemoveBG(srcImgMat, rstMat, nBGStart, 255, nNumParticle);
|
|
|
break;
|
|
|
case OTS_AUTOBGREMOVE_TYPE::MIDDLE:
|
|
|
- for (unsigned int i = 0; i < nImgSize; i++)
|
|
|
- {
|
|
|
- if (pSrcImg[i] >= nBGStart && pSrcImg[i] <= nBGEnd)
|
|
|
- {
|
|
|
- pPixel[i] = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pPixel[i] = 255;
|
|
|
- nNumParticle++;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ //RemoveBG_old(srcImgMat, rstMat, nBGStart, nBGEnd, nNumParticle);
|
|
|
+ CVRemoveBG(srcImgMat, rstMat, nBGStart, nBGEnd, nNumParticle);
|
|
|
+
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- int errodDilateParam = 5;
|
|
|
- if (errodDilateParam > 0)
|
|
|
- {
|
|
|
- BErode3(pPixel, pTempImg, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
- BDilate3(pTempImg, pPixel, errodDilateParam, nHeightImg, nWidthImg);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
a_pBinImgOut->SetImageData(pPixel,nWidthImg,nHeightImg);
|