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; }
这是本人在MFC应用程序中对一个图像进行分割,要用矩形框在图像上标出分割区域,分割的区域像素点都存储在regions容器里,现在就不知道怎么把那个矩形框画出来,需要在::OnDraw(CDC* pDC)里写出画矩形框的代码,求各位高手指点一下!
解决方案
30
CDC::FrameRect
void FrameRect( LPCRECT lpRect, CBrush* pBrush );
Parameters
lpRect
Points to a RECT structure or CRect object that contains the logical coordinates of the upper-left and lower-right corners of the rectangle. You can also pass a CRect object for this parameter.
pBrush
Identifies the brush to be used for framing the rectangle.
Remarks
Draws a border around the rectangle specified by lpRect. The function uses the given brush to draw the border. The width and height of the border is always 1 logical unit.
If the rectangle’s bottom coordinate is less than or equal to top, or if right is less than or equal to left, the rectangle is not drawn.
The border drawn by FrameRect is in the same position as a border drawn by the Rectangle member function using the same coordinates (if Rectangle uses a pen that is 1 logical unit wide). The interior of the rectangle is not filled by FrameRect.
CDC Overview | Class Members | Hierarchy Chart
See Also CBrush,::FrameRect, CDC::Rectangle, CDC::FrameRgn, RECT
void FrameRect( LPCRECT lpRect, CBrush* pBrush );
Parameters
lpRect
Points to a RECT structure or CRect object that contains the logical coordinates of the upper-left and lower-right corners of the rectangle. You can also pass a CRect object for this parameter.
pBrush
Identifies the brush to be used for framing the rectangle.
Remarks
Draws a border around the rectangle specified by lpRect. The function uses the given brush to draw the border. The width and height of the border is always 1 logical unit.
If the rectangle’s bottom coordinate is less than or equal to top, or if right is less than or equal to left, the rectangle is not drawn.
The border drawn by FrameRect is in the same position as a border drawn by the Rectangle member function using the same coordinates (if Rectangle uses a pen that is 1 logical unit wide). The interior of the rectangle is not filled by FrameRect.
CDC Overview | Class Members | Hierarchy Chart
See Also CBrush,::FrameRect, CDC::Rectangle, CDC::FrameRgn, RECT