OpenCV (3) OpenCV Drawing and Annotating
1. Draw a circle:
OpenCV provides some functions to make lines, squares, circles on the top of an image.
For example, we can draw a circle on our image.
#include#include using namespace std; using namespace cv; int main() { Mat img = imread("mini.jpg"); circle( img, // draw on the top of this image Point(100, 60), // center 60, // radius Scalar(0x00, 0x00, 0xFF), // color (BGR) 2 // thickness ); imshow("Image", img); waitKey(0); destroyAllWindows(); return 0; }
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRQjEOEqdvklGkCa96TQa5iQjapQaNlqgCyfECvlMftSckqK7_zkfcJyQb-2IcUvIHkWHiHZYjZQll2abt-IJqOZ55jR-IsIbUPtUV4UcyzbxYxQBoM3aTJ6omkzjK1BiOn0UyX-0GIuE/s320/2018-05-27+21-16-21+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
2. Annotation:
Furthermore, we can put some text on our image.
#include#include using namespace std; using namespace cv; int main() { Mat img = imread("mini.jpg"); circle( img, Point(100, 60), // center 60, // radius Scalar(0x00, 0x00, 0xFF), // color (BGR) 2 // thickness ); putText( img, String("minion A"), // annotation Point(10, 30), // position FONT_HERSHEY_PLAIN, // font 1, // font size Scalar(0x00, 0x00, 0xFF) // color (BGR) ); imshow("Image", img); waitKey(0); destroyAllWindows(); return 0; }
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM-wn4G8l_Zuxjo5uMayHD4NPtVIShRMST2gqTtzmvZGgGynPTNQEdEbOLCKWqMPvfh6k4EDgt4vTyNXDEKFcyKdeVowOIfho48bWurm-WzkqEqg7LXDLPwEySNiM4CL7XTNcQXpj5Ni8/s320/2018-05-27+21-31-58+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
Reference
[1] Adrian Kaehler, Gary Bradski, Learning OpenCV 3 , O'Reilly Media (2017)