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

本站现有博文324篇,共被浏览811585

本站已经建立2515天!

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