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);
}