日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python opencv-4.1.0 cv2.getTextSize()函数 (计算文本字符串的宽度和高度)

發(fā)布時間:2025/3/19 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python opencv-4.1.0 cv2.getTextSize()函数 (计算文本字符串的宽度和高度) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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: :計算并返回包含指定文本的框的大小。。 也就是說,以下代碼呈現(xiàn)了一些文本,其周圍的緊框和基線:. @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.用于渲染文本的線的粗細(xì)。 有關(guān)詳細(xì)信息,請參見#putText。. @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text. point. 基線相對于最底下的文本點的y坐標(biāo)。. @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我也不知道是啥意思。。。

總結(jié)

以上是生活随笔為你收集整理的python opencv-4.1.0 cv2.getTextSize()函数 (计算文本字符串的宽度和高度)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。