python
from google.colab import files
from google.colab import drive
drive.mount('/content/drive')
img = cv2.imread("/content/drive/My Drive/Colab Notebooks/img/Lenna.bmp")
python
import cv2 #opencv
import matplotlib.pyplot as plt #I want the coordinates to check the result, so I use it
%matplotlib inline
python
#Write information settings
pt1 = (50,50)
pt2 = (200,50)
color = (255,0,0)
fontcolor = (0,0,255)
width = 5
fontsize = 0.7
fontwidth = 2
r = 10
fontface = cv2.FONT_HERSHEY_SIMPLEX#Font type
#Write a line on the image (setting is up)
cv2.line(img, pt1, pt2, color,width)
#Write a circle
cv2.circle(img,pt1,r,color,width)#width is-If it is 1, it will be filled.
#Write letters
cv2.putText(img,'Girl is Lenna!',pt1,fontface,fontsize,fontcolor,fontwidth)
#Check the image(Since the RGB order is different between opencv and matplot, it is converted and displayed.)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
The width of the line is literally the same width, not the plus or minus width. The diameter of the circle must be specified by the radius. The coordinate start point of the character is the lower left of the character by default. If you want to change it, specify bottomLeftOrigin = True The starting point is on the upper left. However, the letters are also turned over.
Recommended Posts