python opencv-4.1.0 cv2.getTextSize()函数 (计算文本字符串的宽度和高度)
生活随笔
收集整理的這篇文章主要介紹了
python opencv-4.1.0 cv2.getTextSize()函数 (计算文本字符串的宽度和高度)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
def getTextSize(text, fontFace, fontScale, thickness): # real signature unknown; restored from __doc__"""getTextSize(text, fontFace, fontScale, thickness) -> retval, baseLine. @brief Calculates the width and height of a text string.計算文本字符串的寬度和高度。. . The function cv::getTextSize calculates and returns the size of a box that contains the specified text.. That is, the following code renders some text, the tight box surrounding it, and the baseline: :計算并返回包含指定文本的框的大小。。 也就是說,以下代碼呈現了一些文本,其周圍的緊框和基線:. @code. String text = "Funny text inside the box";. int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;. double fontScale = 2;. int thickness = 3;. . Mat img(600, 800, CV_8UC3, Scalar::all(0));. . int baseline=0;. Size textSize = getTextSize(text, fontFace,. fontScale, thickness, &baseline);. baseline += thickness;. . // center the text 文字居中. Point textOrg((img.cols - textSize.width)/2,. (img.rows + textSize.height)/2);. . // draw the box 畫盒子. rectangle(img, textOrg + Point(0, baseline),. textOrg + Point(textSize.width, -textSize.height),. Scalar(0,0,255));. // ... and the baseline first 首先是基線. line(img, textOrg + Point(0, thickness),. textOrg + Point(textSize.width, thickness),. Scalar(0, 0, 255));. . // then put the text itself 然后把文字本身. putText(img, text, textOrg, fontFace, fontScale,. Scalar::all(255), thickness, 8);. @endcode. . @param text Input text string. 輸入文字字符串。. @param fontFace Font to use, see #HersheyFonts. 要使用的字體,請參見#HersheyFonts。. @param fontScale Font scale factor that is multiplied by the font-specific base size.字體比例因子,用來被特定字體的基本大小相乘。. @param thickness Thickness of lines used to render the text. See #putText for details.用于渲染文本的線的粗細。 有關詳細信息,請參見#putText。. @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text. point. 基線相對于最底下的文本點的y坐標。. @return The size of a box that contains the specified text. 包含指定文本的框的大小。. . @see putText"""pass
示例:
t_size = cv2.getTextSize(bbox_mess, 0, fontScale, thickness=bbox_thick // 2)[0]fontFace寫成0我也不知道是啥意思。。。
總結
以上是生活随笔為你收集整理的python opencv-4.1.0 cv2.getTextSize()函数 (计算文本字符串的宽度和高度)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python opencv-4.1.0
- 下一篇: 文本行中的基线(baseline)、底线