你可以使用这个逻辑。
import cv2
import numpy as np
your_text = ['I', 'am', 'extracting', 'text', 'from', 'handwritten', 'text', 'images', 'using', 'Google', 'OCR', 'API.',
'but', 'I', 'want', 'to', 'print', 'those', 'text', 'in', 'another', 'blank', 'image', 'with',
'respective', 'their', 'coordinates', 'on', 'the', 'original', 'image.']
blank_image = np.zeros((400, 400))
height, width = blank_image.shape
FONT_SCALE = 0.6
FONT = cv2.FONT_HERSHEY_SIMPLEX
FONT_THICKNESS = 1
word_x, word_y = 20, 20 # Origin cordinate of text
height_spacing = 5 # space between 2 string
for word in your_text:
(label_width, label_height), baseline = cv2.getTextSize(word + " ", FONT, FONT_SCALE, FONT_THICKNESS)
if word_x + label_width > width:
word_x = 0
word_y += label_height + height_spacing
cv2.putText(blank_image, word + " ", (word_x, word_y), FONT, FONT_SCALE, 255, FONT_THICKNESS)
word_x += label_width
cv2.imshow("text image", blank_image)
cv2.waitKey(0)
cv2.destroyAllWindows()