Thursday , December 2 2021
Home / Computer Vision / Displaying text on Image in Python using OpenCV

Displaying text on Image in Python using OpenCV

8 Displaying Text on Image

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true,
        processEnvironments: true
    },
    // Center justify equations in code and markdown cells. Elsewhere
    // we use CSS to left justify single line equations in code cells.
    displayAlign: 'center',
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}},
        linebreaks: { automatic: true }
    }
});
</script>
<!-- End of mathjax configuration --></head>

Displaying text on Image in Python using OpenCV

putText() Function takes in 7 arguments –

  • Image
  • Text to be displayed
  • Bottom-left corner co-ordinates, from where the text should start
  • Font
  • Font size
  • Color (BGR format)
  • Line width

In [2]:

import cv2
img = cv2.imread('machinelearning.png',1)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

In [3]:

import cv2
img = cv2.imread('machinelearning.png',1)

output = img.copy() 
text = cv2.putText(output, 'www.machinelearning.org.in', (120, 25),  cv2.FONT_HERSHEY_SIMPLEX, 1, (60, 60, 60), 2)

cv2.imshow('Machine Learning',text)
cv2.waitKey(0)
cv2.destroyAllWindows()

About Machine Learning

Check Also

Record Video From a Webcam using OpenCV

12 Record Video using OpenCV Record Video From a Webcam using OpenCV¶ cv2.VideoWriter( filename, fourcc, …

Leave a Reply

Your email address will not be published. Required fields are marked *