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

本站现有博文343篇,共被浏览1066544次

本站已经建立2733天!

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