使用 putText() 函式在 OpenCV 視窗顯示文字


在本教程中,我們將使用 opencv 函式 putText() 在影像上書寫文字。此函式帶入影像、字型、文字位置座標、顏色、粗細等。

原始影像

演算法

Step 1: Import cv2
Step 2: Define the parameters for the puttext( ) function.
Step 3: Pass the parameters in to the puttext() function.
Step 4: Display the image.

程式碼示例

import cv2
image = cv2.imread("testimage.jpg")
text = "TutorialsPoint"
coordinates = (100,100)
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
color = (255,0,255)
thickness = 2
image = cv2.putText(image, text, coordinates, font, fontScale, color, thickness, cv2.LINE_AA)
cv2.imshow("Text", image)

輸出

更新時間:2021 年 3 月 17 日

5 千 + 次訪問

開啟你的 職業生涯

完成課程後獲得認證

開始學習
廣告