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

本站现有博文316篇,共被浏览747621

本站已经建立2396天!

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