Draw Circle on Image using OpenCV

Draw Circle on Image using OpenCV

OpenCV offers many drawing functions that can be used to draw various geometric shapes such as line, rectangle, circle, etc.

The circle function can be used to draw a circle by specifying center x and y coordinates and radius.

import cv2
import numpy as np

img = np.zeros((100, 300, 3), dtype=np.uint8)

x, y = 150, 50
radius = 40
cv2.circle(img, (x, y), radius, (0, 255, 0), 2)

cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
#include <opencv2/opencv.hpp>

using namespace cv;

int main()
{
    Mat img = Mat::zeros(100, 300, CV_8UC3);

    int x = 150, y = 50;
    int radius = 40;
    circle(img, Point(x, y), radius, Scalar(0, 255, 0), 2);

    imshow("Image", img);
    waitKey(0);
    destroyAllWindows();

    return 0;
}
package app;

import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;

public class Main
{
    static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }

    public static void main(String[] args)
    {
        Mat img = Mat.zeros(100, 300, CvType.CV_8UC3);

        int x = 150, y = 50;
        int radius = 40;
        Imgproc.circle(img, new Point(x, y), radius, new Scalar(0, 255, 0), 2);

        HighGui.imshow("Image", img);
        HighGui.waitKey(0);
        HighGui.destroyAllWindows();

        System.exit(0);
    }
}

Result:

Draw circle on image using OpenCV

Leave a Comment

Cancel reply

Your email address will not be published.