Opencv学习----几何对象的绘制

4.3.5 几何对象的绘制

cv::Mat* mat = new Mat(m_height, m_width, CV_8UC4);

4.3.5.1 绘制线

void ES::OESGeometryElem::showLine(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_8;
	cv::Point start(0, heigth / 2);
	cv::Point end(width, heigth / 2);
	line(*mat, start, end, Scalar(0, 0, 255), thickness, lineType);
	cv::Point start1(width / 2, 0);
	cv::Point end1(width / 2, heigth);
	line(*mat, start1, end1, Scalar(255, 0, 0), thickness, lineType);
}

4.3.5.2 绘制带箭头的线

void ES::OESGeometryElem::showArrowedLine(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_8;
	cv::Point start(width / 4, heigth / 2);
	cv::Point end(width / 4 * 3, heigth / 2);
	arrowedLine(*mat, start, end, Scalar(0, 0, 255), thickness, lineType);
	cv::Point start1(width / 2, heigth / 4);
	cv::Point end1(width / 2, heigth / 4 * 3);
	arrowedLine(*mat, start1, end1, Scalar(255, 0, 0), thickness, lineType);
}

4.3.5.3 绘制矩形

void ES::OESGeometryElem::showRectangle(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_8;
	cv::Point start(width / 4, heigth / 4);
	cv::Point end(width / 4 * 3, heigth / 4 * 3);
	rectangle(*mat, start, end, Scalar(0, 0, 255), thickness, lineType);
}

4.3.5.4 绘制圆

void ES::OESGeometryElem::showCircle(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_8;
	cv::Point center(width / 2, heigth / 2);
	int radius = heigth / 4;
	circle(*mat, center, radius, Scalar(0, 0, 255), thickness, lineType);
}

4.3.5.5 绘制椭圆

void ES::OESGeometryElem::showEllipse(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_AA;
	cv::Point center(width / 2, heigth / 2);
	Size axes = Size(width / 4, heigth / 4);
	ellipse(*mat, center, axes, 0, 0, 360, Scalar(0, 0, 255), thickness, lineType);
}

4.3.5.5 绘制标记

void ES::OESGeometryElem::showMark(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_AA;
	cv::Point center(width / 4, heigth / 2);
	int markerType = MARKER_CROSS;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
	center.x += 40;
	markerType = MARKER_TILTED_CROSS;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
	center.x += 40;
	markerType = MARKER_STAR;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
	center.x += 40;
	markerType = MARKER_DIAMOND;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
	center.x += 40;
	markerType = MARKER_SQUARE;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
	center.x += 40;
	markerType = MARKER_TRIANGLE_UP;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
	center.x += 40;
	markerType = MARKER_TRIANGLE_DOWN;
	drawMarker(*mat, center, Scalar(0, 0, 255), markerType);
}

4.3.5.5 绘制填充的凸多边形

void ES::OESGeometryElem::showFilledConvexPoly(cv::Mat* mat)
{
	std::vector<Point> pts = { 
		Point(100, 100), 
		Point(200, 100), 
		Point(220, 150), 
		Point(180, 200), 
		Point(50, 200),
		Point(100, 100)
	};
	int lineType = LINE_8;
	fillConvexPoly(*mat, pts, Scalar(0, 0, 255), lineType);
}

4.3.5.5 绘制填充的任意多边形

void ES::OESGeometryElem::showFilledPoly(cv::Mat* mat)
{
	Point pts[1][6] = { {
		Point(100, 100),
		Point(200, 100),
		Point(180, 150),
		Point(220, 200),
		Point(50, 200),
		Point(100, 100)
	} };
	const Point* ppt[1] = { pts[0] };
	int npt[] = { 6 };

	int lineType = LINE_8;
	fillPoly(*mat, ppt, npt, 1, Scalar(0, 0, 255), lineType);
}

4.3.5.5 绘制任意多边形路径

void ES::OESGeometryElem::showPolylines(cv::Mat* mat)
{
	std::vector<std::vector<Point>> pts = { {
		Point(100, 100),
		Point(200, 100),
		Point(220, 150),
		Point(180, 200),
		Point(50, 200)
	} };
	int lineType = LINE_AA;
	int thickness = 1;
	polylines(*mat, pts, false, Scalar(0, 0, 255), thickness, lineType);
	std::vector<std::vector<Point>> pts1 = { {
			Point(100, 100 + 120),
			Point(200, 100 + 120),
			Point(220, 150 + 120),
			Point(180, 200 + 120),
			Point(50, 200 + 120)
		} };
	polylines(*mat, pts1, true, Scalar(0, 0, 255), thickness, lineType);
}

4.3.5.5 绘制文字

void ES::OESGeometryElem::showText(cv::Mat* mat)
{
	int width = m_view->getWidth();
	int heigth = m_view->getHeight();
	int thickness = 1;
	int lineType = LINE_AA;
	std::string str = "Opencv";
	cv::Point org(width / 2, heigth / 4);
	double fontScale = 1.0;
	int fontFace = HersheyFonts::FONT_HERSHEY_SIMPLEX;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_PLAIN;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_DUPLEX;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_COMPLEX;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_TRIPLEX;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_COMPLEX_SMALL;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_SCRIPT_SIMPLEX;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_HERSHEY_SCRIPT_COMPLEX;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
	fontFace = HersheyFonts::FONT_ITALIC;
	org.y += 40;
	putText(*mat, str, org, fontFace, fontScale, Scalar(0, 0, 255), thickness, lineType);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dylan55_you

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值