64,663
社区成员
发帖
与我相关
我的任务
分享
int CMSERSeg::MserSegment(WORD *MserLabelImage, int nCharHeight, vector<vector<Point>> regions)
{
memset(MserLabelImage,0,sizeof(WORD)*m_nH*m_nW);
Mat grayImg, colorImg;
//BYTE数据转换为Mat;
if(m_nChannels>1)
colorImg = Mat(m_nH,m_nW,CV_8UC3,m_pData);
else
grayImg = Mat(m_nH,m_nW,CV_8UC1,m_pData);
//MSER初始化
MSER ms(1, // _delta=5//old=1
nCharHeight*2.5,//_min_area//old=nCharHeight*2.5
//120, //_min_area=60
nCharHeight*15,//_max_area//old=nCharHeight*15
//520,// _max_area=14400
0.1,//_max_variation=0.25//old=0.1
0.1,//_min_diversity=.2//old=0.1
//for color image:
10,//_max_evolution=200//old=10
1.01,//_area_threshold=1.01//old=10
0.003,// _min_margin=0.003//old=0.003
5);// _edge_blur_size=5//old=0
//用应区域的像素点集;
// vector<vector<Point>> regions;
if(m_nChannels==1)
ms(grayImg,regions,Mat());//分割
else
ms(colorImg,regions,Mat());//分割
int nRegionNum = regions.size();//区域个数;
// 获取标号图;
// Mat LabelImage(m_nH,m_nW,CV_32SC1,Scalar::all(0));
WORD nNum = 0;
vector<vector<Point>>::iterator r1;
for (r1=regions.begin();r1!=regions.end();r1++)
{
vector<Point>::iterator r2;
for (r2=r1->begin();r2!=r1->end();r2++)
MserLabelImage[r2->y*m_nW+r2->x] = nNum;
nNum++;
}
return nRegionNum;
}