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

本站现有博文320篇,共被浏览762195

本站已经建立2436天!

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