EADST

Using OpenCV to Add Chinese Characters in An Image

Using OpenCV to Add Chinese Characters in An Image

# coding=UTF-8
import cv2
import numpy
from PIL import Image, ImageDraw, ImageFont

def cv2ImgAddText(img, text, left, top, textColor=(255, 0, 0), textSize=20):
    if (isinstance(img, numpy.ndarray)):
        img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
    draw = ImageDraw.Draw(img)
    fontText = ImageFont.truetype("simfang.ttf", textSize, encoding="utf-8") # you need to change the font path
    draw.text((left, top), text, textColor, font=fontText)
    return cv2.cvtColor(numpy.asarray(img), cv2.COLOR_RGB2BGR)


img = cv2.imread("test.jpg")
img = cv2ImgAddText(img, "大家好", 140, 60, (255, 0, 0), 20)
cv2.imwrite("test_result.jpg", img)
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
Algorithm Clash FP8 净利润 Quantize Base64 PIP SVR Input diffusers Numpy PDB Password VGG-16 Datetime CV CLAP WebCrawler Linux PDF 阿里云 API 飞书 Attention Tensor Bert 第一性原理 Review UNIX torchinfo Mixtral Magnet Augmentation Qwen2.5 FlashAttention Data Pandas Pickle 报税 VPN Conda Use uwsgi Web Excel Heatmap Sklearn Bin Paper transformers Safetensors 域名 CTC Image2Text Food tqdm LeetCode Cloudreve ChatGPT v0.dev Crawler FP64 Land GPT4 v2ray PyTorch Plotly Agent Nginx News DeepStream Interview OpenCV 多线程 音频 Git Proxy XGBoost Python 递归学习法 Hotel Jetson Windows DeepSeek Hilton 算法题 LLAMA Markdown SAM WAN Permission GGML Github Vim ModelScope LaTeX 继承 Baidu GIT Translation Ubuntu Random SQLite NLTK TSV Miniforge AI Transformers Django BTC FastAPI Freesound Bitcoin Math Diagram Gemma git Ptyhon JSON Streamlit BeautifulSoup Jupyter RAR Website 搞笑 Vmess 关于博主 FP32 Statistics 公式 uWSGI FP16 NLP IndexTTS2 Tiktoken UI 证件照 CEIR QWEN OpenAI Quantization VSCode Search Domain Claude GPTQ Plate ResNet-50 C++ scipy InvalidArgumentError OCR XML 顶会 MD5 LoRA git-lfs CC TensorRT Pillow Qwen2 Shortcut Tracking PyCharm 图标 CUDA CAM ONNX Llama Disk Michelin Firewall 图形思考法 TensorFlow NameSilo HuggingFace 云服务器 强化学习 TTS 财报 Pytorch tar Distillation Color YOLO Video Hungarian Dataset 版权 CSV Template printf Paddle Zip llama.cpp logger Knowledge mmap 多进程 LLM Breakpoint icon Animate 签证 Anaconda 腾讯云 SQL Card Google Docker RGB Logo COCO EXCEL SPIE hf BF16 Qwen HaggingFace Bipartite GoogLeNet
站点统计

本站现有博文322篇,共被浏览784960

本站已经建立2479天!

热门文章
文章归档
回到顶部