Skip to main content

Like cv2.putText, but with TrueType Fonts (ttf)

Project description

cv2.putTrueTypeText works just like cv2.putText, but with TTF fonts!

You can add putTrueTypeText to cv2, or ...

$pip install a_cv2_putTrueTypeText



from a_cv_imwrite_imread_plus import add_imwrite_plus_imread_plus_to_cv2

from random import choice

from a_cv2_imshow_thread import add_imshow_thread_to_cv2

from a_cv2_putTrueTypeText import add_truetypetext_to_cv2, get_all_ttf_fonts

import cv2

add_imshow_thread_to_cv2()

add_truetypetext_to_cv2()

add_imwrite_plus_imread_plus_to_cv2()





url = r"https://raw.githubusercontent.com/hansalemaos/screenshots/main/templatematching1.png"

filepath = "c:\\temptemptemppic.png"

pic = cv2.imread_plus(url)

cv2.imwrite_plus(filepath, pic)

ttfonts = get_all_ttf_fonts()







font1 = choice(ttfonts)

test1 = cv2.putTrueTypeText(

    img=filepath,

    text=f"{font1}".lower(),

    org=(50, 120),

    fontFace=font1, #needs to be a file path!

    fontScale=46,

    color=(255, 255, 0),

)



font2 = choice(ttfonts)

test2 = cv2.putTrueTypeText(

    img=url,

    text=f"{font2}".lower(),

    org=(50, 120),

    fontFace=font2,

    fontScale=46,

    color=(255, 0, 255),

)



font3 = choice(ttfonts)

test3 = cv2.putTrueTypeText(

    img=cv2.imread(filepath),

    text=f"{font3}".lower(),

    org=(50, 120),

    fontFace=font3,

    fontScale=46,

    color=(123, 50, 110),

)



font4 = choice(ttfonts)



test4 = cv2.putTrueTypeText(

    img=cv2.imread(filepath, cv2.IMREAD_GRAYSCALE),

    text=f"{font4}".lower(),

    org=(50, 120),

    fontFace=font4,

    fontScale=46,

    color=(255, 0, 255),

)





test5 = cv2.putTrueTypeText(

    img=cv2.imread(filepath),

    text=f"cv2.FONT_HERSHEY_SIMPLEX",

    org=(50, 120),

    fontFace=cv2.FONT_HERSHEY_SIMPLEX,

    fontScale=2,

    color=(255, 0, 255),

)





cv2.imshow_thread([test1, test2, test3, test4, test5])

... import the function

from a_cv_imwrite_imread_plus import add_imwrite_plus_imread_plus_to_cv2

from random import choice

from a_cv2_imshow_thread import add_imshow_thread_to_cv2

from a_cv2_putTrueTypeText import putTrueTypeText, get_all_ttf_fonts

import cv2

add_imwrite_plus_imread_plus_to_cv2()





url = r"https://raw.githubusercontent.com/hansalemaos/screenshots/main/templatematching1.png"

filepath = "c:\\temptemptemppic.png"

pic = cv2.imread_plus(url)

cv2.imwrite_plus(filepath, pic)

ttfonts = get_all_ttf_fonts()

add_imshow_thread_to_cv2()





font1 = choice(ttfonts)

test1 = putTrueTypeText(

    img=filepath,

    text=f"{font1}".lower(),

    org=(50, 120),

    fontFace=font1, #needs to be a file path!

    fontScale=46,

    color=(255, 255, 0),

)



font2 = choice(ttfonts)

test2 = putTrueTypeText(

    img=url,

    text=f"{font2}".lower(),

    org=(50, 120),

    fontFace=font2,

    fontScale=46,

    color=(255, 0, 255),

)



font3 = choice(ttfonts)

test3 = putTrueTypeText(

    img=cv2.imread(filepath),

    text=f"{font3}".lower(),

    org=(50, 120),

    fontFace=font3,

    fontScale=46,

    color=(123, 50, 110),

)



font4 = choice(ttfonts)



test4 = putTrueTypeText(

    img=cv2.imread(filepath, cv2.IMREAD_GRAYSCALE),

    text=f"{font4}".lower(),

    org=(50, 120),

    fontFace=font4,

    fontScale=46,

    color=(255, 0, 255),

)





test5 = putTrueTypeText(

    img=cv2.imread(filepath),

    text=f"cv2.FONT_HERSHEY_SIMPLEX",

    org=(50, 120),

    fontFace=cv2.FONT_HERSHEY_SIMPLEX,

    fontScale=2,

    color=(255, 0, 255),

)





cv2.imshow_thread([test1, test2, test3, test4, test5])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

a_cv2_putTrueTypeText-0.10.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

a_cv2_putTrueTypeText-0.10-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file a_cv2_putTrueTypeText-0.10.tar.gz.

File metadata

  • Download URL: a_cv2_putTrueTypeText-0.10.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for a_cv2_putTrueTypeText-0.10.tar.gz
Algorithm Hash digest
SHA256 162c977c71e83ea0569ed64f4047faab24d99f8137db921410b7f1e6e28c634c
MD5 4b71b1b420f7ce4987dad154023281f3
BLAKE2b-256 3d2b748c78d32adb81876a4e80475772a76abb5d46f51a354b65fa9fbec0b54f

See more details on using hashes here.

File details

Details for the file a_cv2_putTrueTypeText-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for a_cv2_putTrueTypeText-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b68553aaf118894cb14365442f26b644f346cd8ddd0a9e7c8225a6986e30c80b
MD5 506fd31a5bd39b7ef4f2f3cc2face693
BLAKE2b-256 26ae28ee2ea97b5e5e00f1eba2daae218dd7a8573195ef2665934450bb2901d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page