图像分割与画矩形框标记

qq_29752557 2017-04-09 04:13:40
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)里写出画矩形框的代码,求各位大神指点一下!
...全文
728 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_29752557 2017-04-11
  • 打赏
  • 举报
回复
后来我用迭代器弄出来了,还是谢谢1楼、2楼的。
赵4老师 2017-04-10
  • 打赏
  • 举报
回复
Polygon The Polygon function draws a polygon consisting of two or more vertices connected by straight lines. The polygon is outlined by using the current pen and filled by using the current brush and polygon fill mode. BOOL Polygon( HDC hdc, // handle to device context CONST POINT *lpPoints, // pointer to polygon's vertices int nCount // count of polygon's vertices ); Parameters hdc Handle to the device context. lpPoints Pointer to an array of POINT structures that specify the vertices of the polygon. nCount Specifies the number of vertices in the array. This value must be greater than or equal to 2. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks The polygon is closed automatically by drawing a line from the last vertex to the first. The current position is neither used nor updated by the Polygon function. Windows CE: Windows CE version 1.0 supports only convex polygons. This function is the same in Windows CE version 2.0 as it is in Windows desktop platforms. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Filled Shapes Overview, Filled Shape Functions, GetPolyFillMode, POINT, Polyline, PolylineTo, PolyPolygon, SetPolyFillMode
赵4老师 2017-04-10
  • 打赏
  • 举报
回复
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

64,663

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧