1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| #include <opencv2/core.hpp> #include <opencv2/imgproc.hpp> #include <opencv2/highgui.hpp>
#define w 400 #define h 500
void MyEllipse(cv::Mat img, double angle); void MyCircle(cv::Mat img, cv::Point center); void MyPolygon(cv::Mat img); void MyRectangle(cv::Mat img); void MyLine(cv::Mat img, cv::Point start, cv::Point end);
int main() {
cv::Mat rook_image = cv::Mat::zeros(h, w, CV_8UC3); MyPolygon(rook_image); MyRectangle(rook_image); MyLine( rook_image, cv::Point( 0, 15*w/16 ), cv::Point( w, 15*w/16 ) ); MyLine( rook_image, cv::Point( w/4, 7*w/8 ), cv::Point( w/4, w ) ); MyLine( rook_image, cv::Point( w/2, 7*w/8 ), cv::Point( w/2, w ) ); MyLine( rook_image, cv::Point( 3*w/4, 7*w/8 ), cv::Point( 3*w/4, w ) ); cv::imshow("rook", rook_image); cv::moveWindow("rook", 2000, 800 ); cv::waitKey(); }
void MyEllipse(cv::Mat img, double angle) { int thickness = 2; int lineType = 4; cv::ellipse(img, cv::Point(w/2, w/2), cv::Size(w/4, w/16), angle, 0, 360, cv::Scalar( 255, 0, 0 ), thickness, lineType); }
void MyCircle(cv::Mat img, cv::Point center) { cv::circle(img, center, w/32, cv::Scalar(0, 0, 255), 2, 16); }
void MyRectangle(cv::Mat img) { cv::rectangle(img, cv::Point(0, 7*w/8), cv::Point(w, w), cv::Scalar(0, 255, 255), -1, 8); }
void MyPolygon(cv::Mat img) { cv::Point rook_points[1][20]; rook_points[0][0] = cv::Point( w/4, 7*w/8 ); rook_points[0][1] = cv::Point( 3*w/4, 7*w/8 ); rook_points[0][2] = cv::Point( 3*w/4, 13*w/16 ); rook_points[0][3] = cv::Point( 11*w/16, 13*w/16 ); rook_points[0][4] = cv::Point( 19*w/32, 3*w/8 ); rook_points[0][5] = cv::Point( 3*w/4, 3*w/8 ); rook_points[0][6] = cv::Point( 3*w/4, w/8 ); rook_points[0][7] = cv::Point( 26*w/40, w/8 ); rook_points[0][8] = cv::Point( 26*w/40, w/4 ); rook_points[0][9] = cv::Point( 22*w/40, w/4 ); rook_points[0][10] = cv::Point( 22*w/40, w/8 ); rook_points[0][11] = cv::Point( 18*w/40, w/8 ); rook_points[0][12] = cv::Point( 18*w/40, w/4 ); rook_points[0][13] = cv::Point( 14*w/40, w/4 ); rook_points[0][14] = cv::Point( 14*w/40, w/8 ); rook_points[0][15] = cv::Point( w/4, w/8 ); rook_points[0][16] = cv::Point( w/4, 3*w/8 ); rook_points[0][17] = cv::Point( 13*w/32, 3*w/8 ); rook_points[0][18] = cv::Point( 5*w/16, 13*w/16 ); rook_points[0][19] = cv::Point( w/4, 13*w/16 ); const cv::Point* ppt[1] = {rook_points[0]}; int npt[] = {20}; cv::fillPoly(img, ppt, npt, 1, cv::Scalar( 255, 255, 255 ), 8);
}
void MyLine(cv::Mat img, cv::Point start, cv::Point end) { int thickness = 2; int lineType = cv::LINE_8; cv::line(img, start, end, cv::Scalar(0, 0, 0), thickness, lineType); }
|