opencv::绘制-基本几何

 

画线   cv::line(LINE_4\LINE_8\LINE_AA)
画椭圆 cv::ellipse
画矩形 cv::rectangle
画圆   cv::circle
画填充 cv::fillPoly

 

    putText(bgImage, "Hello OpenCV 你好 ", Point(300, 300), CV_FONT_HERSHEY_COMPLEX, 1.0, Scalar(12, 23, 200), 3, 8);

 

void MyLines() {
    Point p1 = Point(20, 30);
    Point p2;
    p2.x = 400;
    p2.y = 400;
    Scalar color = Scalar(0, 0, 255);
    line(bgImage, p1, p2, color, 1, LINE_AA);
}

void MyRectangle() {
    Rect rect = Rect(200, 100, 300, 300);
    Scalar color = Scalar(255, 0, 0);
    rectangle(bgImage, rect, color, 2, LINE_8);
}

void MyEllipse() {
    Scalar color = Scalar(0, 255, 0);
    ellipse(bgImage, Point(bgImage.cols / 2, bgImage.rows / 2), Size(bgImage.cols / 4, bgImage.rows / 8), 90, 0, 360, color, 2, LINE_8);
}

void MyCircle() {
    Scalar color = Scalar(0, 255, 255);
    Point center = Point(bgImage.cols / 2, bgImage.rows / 2);
    circle(bgImage, center, 150, color, 2, 8);
}

void MyPolygon() {
    Point pts[1][5];
    pts[0][0] = Point(100, 100);
    pts[0][1] = Point(100, 200);
    pts[0][2] = Point(200, 200);
    pts[0][3] = Point(200, 100);
    pts[0][4] = Point(100, 100);

    const Point* ppts[] = { pts[0] };
    int npt[] = { 5 };
    Scalar color = Scalar(255, 12, 255);

    fillPoly(bgImage, ppts, npt, 1, color, 8);
}

void RandomLineDemo() {
    RNG rng(12345);
    Point pt1;
    Point pt2;
    Mat bg = Mat::zeros(bgImage.size(), bgImage.type());
    namedWindow("random line demo", CV_WINDOW_AUTOSIZE);
    for (int i = 0; i < 100000; i++) {
        pt1.x = rng.uniform(0, bgImage.cols);
        pt2.x = rng.uniform(0, bgImage.cols);
        pt1.y = rng.uniform(0, bgImage.rows);
        pt2.y = rng.uniform(0, bgImage.rows);
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        if (waitKey(50) > 0) {
            break;
        }
        line(bg, pt1, pt2, color, 1, 8);
        imshow("random line demo", bg);
    }
}

 

int drawRandomLines(Mat image) {
    RNG rng(0xffffff);
    Point pt1, pt2;
    for (int i = 0; i < 100000; i++) {
        pt1.x = rng.uniform(0, image.cols);
        pt2.x = rng.uniform(0, image.cols);
        pt1.y = rng.uniform(0, image.rows);
        pt2.y = rng.uniform(0, image.rows);
        int r = rng.uniform(0, 255);
        int g = rng.uniform(0, 255);
        int b = rng.uniform(0, 255);
        line(image, pt1, pt2, Scalar(b, g, r), 1, LINE_8);
        putText(image, "Open CV Core Tutorial", Point(image.cols / 2 - 200, image.rows / 2),
            CV_FONT_HERSHEY_PLAIN, 2.0, Scalar(0, 255, 0), 3, LINE_8);

        imshow(WINTITLE, image);
        if (waitKey(10) >= 0)
        {
            return -1;
        }
    }
    return 0;
}

 

posted @ 2019-09-03 16:10  osbreak  阅读(249)  评论(0编辑  收藏  举报