OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
繪圖函式

詳細描述

繪圖函式適用於任意深度的矩陣/影像。圖形的邊界可以進行抗鋸齒渲染(目前僅針對8點陣圖像實現)。所有函式都包含一個 `color` 引數,彩色影像使用RGB值(可以透過 Scalar 建構函式構建),灰度影像使用亮度值。對於彩色影像,通道順序通常是 藍色、綠色、紅色。這是 imshow、imread 和 imwrite 所期望的。因此,如果您使用 Scalar 建構函式構建顏色,它應該看起來像

\[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\]

如果您使用自己的影像渲染和I/O函式,可以使用任何通道順序。繪圖函式獨立處理每個通道,不依賴於通道順序,甚至不依賴於所使用的色彩空間。整個影像可以使用 cvtColor 從BGR轉換為RGB或轉換為不同的色彩空間。

如果繪製的圖形部分或完全超出影像,繪圖函式會對其進行裁剪。此外,許多繪圖函式可以處理以子畫素精度指定的畫素座標。這意味著座標可以作為編碼為整數的定點數傳遞。小數位數由 shift 引數指定,實際點座標計算為 \(\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\)。此功能在渲染抗鋸齒圖形時特別有效。

注意
當目標影像是4通道時,這些函式不支援alpha透明度。在這種情況下,color[3] 會被直接複製到重繪的畫素。因此,如果您想繪製半透明圖形,可以在單獨的緩衝區中繪製它們,然後將其與主影像混合。

類  cv::LineIterator
 用於遍歷柵格線段上所有畫素的類。更多...
 

#define CV_RGB(r, g, b)
 

列舉

列舉  cv::HersheyFonts {
  cv::FONT_HERSHEY_SIMPLEX = 0 ,
  cv::FONT_HERSHEY_PLAIN = 1 ,
  cv::FONT_HERSHEY_DUPLEX = 2 ,
  cv::FONT_HERSHEY_COMPLEX = 3 ,
  cv::FONT_HERSHEY_TRIPLEX = 4 ,
  cv::FONT_HERSHEY_COMPLEX_SMALL = 5 ,
  cv::FONT_HERSHEY_SCRIPT_SIMPLEX = 6 ,
  cv::FONT_HERSHEY_SCRIPT_COMPLEX = 7 ,
  cv::FONT_ITALIC = 16
}
 
列舉  cv::LineTypes {
  cv::FILLED = -1 ,
  cv::LINE_4 = 4 ,
  cv::LINE_8 = 8 ,
  cv::LINE_AA = 16
}
 
列舉  cv::MarkerTypes {
  cv::MARKER_CROSS = 0 ,
  cv::MARKER_TILTED_CROSS = 1 ,
  cv::MARKER_STAR = 2 ,
  cv::MARKER_DIAMOND = 3 ,
  cv::MARKER_SQUARE = 4 ,
  cv::MARKER_TRIANGLE_UP = 5 ,
  cv::MARKER_TRIANGLE_DOWN = 6
}
 

函式

void cv::arrowedLine (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int line_type=8, int shift=0, double tipLength=0.1)
 繪製從第一個點指向第二個點的箭頭線段。
 
void cv::circle (InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 Draws a circle.
 
bool cv::clipLine (Rect imgRect, Point &pt1, Point &pt2)
 
bool cv::clipLine (Size imgSize, Point &pt1, Point &pt2)
 Clips the line against the image rectangle.
 
bool cv::clipLine (Size2l imgSize, Point2l &pt1, Point2l &pt2)
 
void cv::drawContours (InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
 繪製輪廓線或填充輪廓。
 
void cv::drawMarker (InputOutputArray img, Point position, const Scalar &color, int markerType=MARKER_CROSS, int markerSize=20, int thickness=1, int line_type=8)
 在影像中的預定義位置繪製標記。
 
void cv::ellipse (InputOutputArray img, const RotatedRect &box, const Scalar &color, int thickness=1, int lineType=LINE_8)
 
void cv::ellipse (InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 繪製簡單或粗橢圓弧或填充橢圓扇區。
 
void cv::ellipse2Poly (Point center, Size axes, int angle, int arcStart, int arcEnd, int delta, std::vector< Point > &pts)
 用多邊形逼近橢圓弧。
 
void cv::ellipse2Poly (Point2d center, Size2d axes, int angle, int arcStart, int arcEnd, int delta, std::vector< Point2d > &pts)
 
void cv::fillConvexPoly (InputOutputArray img, const Point *pts, int npts, const Scalar &color, int lineType=LINE_8, int shift=0)
 
void cv::fillConvexPoly (InputOutputArray img, InputArray points, const Scalar &color, int lineType=LINE_8, int shift=0)
 填充凸多邊形。
 
void cv::fillPoly (InputOutputArray img, const Point **pts, const int *npts, int ncontours, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
 
void cv::fillPoly (InputOutputArray img, InputArrayOfArrays pts, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
 填充一個或多個多邊形所包圍的區域。
 
double cv::getFontScaleFromHeight (const int fontFace, const int pixelHeight, const int thickness=1)
 計算用於達到給定畫素高度的字型特定大小。
 
Size cv::getTextSize (const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
 計算文字字串的寬度和高度。
 
void cv::line (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 繪製連線兩點的線段。
 
void cv::polylines (InputOutputArray img, const Point *const *pts, const int *npts, int ncontours, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 
void cv::polylines (InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 繪製多條多邊形曲線。
 
void cv::putText (InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
 繪製文字字串。
 
void cv::rectangle (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 繪製一個簡單、粗或填充的矩形。
 
void cv::rectangle (InputOutputArray img, Rect rec, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 

宏定義文件

◆ CV_RGB

#define CV_RGB ( r,
g,
b )

#include <opencv2/imgproc.hpp>

cv::Scalar((b), (g), (r), 0)
Scalar_< double > Scalar
定義 types.hpp:709

OpenCV的顏色通道順序是 BGR[A]

列舉型別文件

◆ HersheyFonts

#include <opencv2/imgproc.hpp>

僅支援 Hershey 字型的一部分 https://en.wikipedia.org/wiki/Hershey_fonts

列舉器
FONT_HERSHEY_SIMPLEX 
Python: cv.FONT_HERSHEY_SIMPLEX

正常大小的無襯線字型

FONT_HERSHEY_PLAIN 
Python: cv.FONT_HERSHEY_PLAIN

小尺寸的無襯線字型

FONT_HERSHEY_DUPLEX 
Python: cv.FONT_HERSHEY_DUPLEX

正常大小的無襯線字型(比 FONT_HERSHEY_SIMPLEX 更復雜)

FONT_HERSHEY_COMPLEX 
Python: cv.FONT_HERSHEY_COMPLEX

正常大小的襯線字型

FONT_HERSHEY_TRIPLEX 
Python: cv.FONT_HERSHEY_TRIPLEX

正常大小的襯線字型(比 FONT_HERSHEY_COMPLEX 更復雜)

FONT_HERSHEY_COMPLEX_SMALL 
Python: cv.FONT_HERSHEY_COMPLEX_SMALL

FONT_HERSHEY_COMPLEX 的縮小版

FONT_HERSHEY_SCRIPT_SIMPLEX 
Python: cv.FONT_HERSHEY_SCRIPT_SIMPLEX

手寫風格字型

FONT_HERSHEY_SCRIPT_COMPLEX 
Python: cv.FONT_HERSHEY_SCRIPT_COMPLEX

FONT_HERSHEY_SCRIPT_SIMPLEX 的更復雜變體

FONT_ITALIC 
Python: cv.FONT_ITALIC

斜體字型標誌

◆ LineTypes

#include <opencv2/imgproc.hpp>

線條型別

列舉器
FILLED 
Python: cv.FILLED
LINE_4 
Python: cv.LINE_4

4連通線

LINE_8 
Python: cv.LINE_8

8 連線線

LINE_AA 
Python: cv.LINE_AA

抗鋸齒線

◆ MarkerTypes

#include <opencv2/imgproc.hpp>

用於 cv::drawMarker 函式的標記型別集合

列舉器
MARKER_CROSS 
Python: cv.MARKER_CROSS

十字標記形狀。

MARKER_TILTED_CROSS 
Python: cv.MARKER_TILTED_CROSS

45度傾斜的十字標記形狀。

MARKER_STAR 
Python: cv.MARKER_STAR

星形標記形狀,十字形和傾斜十字形的組合。

MARKER_DIAMOND 
Python: cv.MARKER_DIAMOND

菱形標記形狀。

MARKER_SQUARE 
Python: cv.MARKER_SQUARE

一個正方形標記形狀。

MARKER_TRIANGLE_UP 
Python: cv.MARKER_TRIANGLE_UP

向上指向的三角形標記形狀。

MARKER_TRIANGLE_DOWN 
Python: cv.MARKER_TRIANGLE_DOWN

向下指向的三角形標記形狀。

函式文件

◆ arrowedLine()

void cv::arrowedLine ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int line_type = 8,
int shift = 0,
double tipLength = 0.1 )
Python
cv.arrowedLine(img, pt1, pt2, color[, thickness[, line_type[, shift[, tipLength]]]]) -> img

#include <opencv2/imgproc.hpp>

繪製從第一個點指向第二個點的箭頭線段。

函式 cv::arrowedLine 在影像中繪製從 pt1 到 pt2 的箭頭。另請參見 line

引數
img影像。
pt1箭頭的起點。
pt2箭頭的指向點。
coloropencv2/ximgproc/fast_line_detector.hpp
thicknessLine thickness.
line_type線條型別。參見 LineTypes
移位 (shift)點座標中的小數位數。
tipLength箭頭尖端相對於箭身長度的比例。

◆ circle()

void cv::circle ( InputOutputArray img,
Point center,
int radius,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.circle(img, center, radius, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

Draws a circle.

函式 cv::circle 繪製一個簡單或填充的圓,具有給定的中心和半徑。

引數
img繪製圓的影像。
center圓的中心。
radius圓的半徑。
color圓的顏色。
thickness圓輪廓的粗細,如果為正。負值(例如 FILLED)表示將繪製一個填充圓。
lineType圓邊界的型別。參見 LineTypes
移位 (shift)中心座標和半徑值中的小數位數。

◆ clipLine() [1/3]

bool cv::clipLine ( Rect imgRect,
Point & pt1,
Point & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

引數
imgRect影像矩形。
pt1線的第一個點。
pt2線的第二個點。

◆ clipLine() [2/3]

bool cv::clipLine ( Size imgSize,
Point & pt1,
Point & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

Clips the line against the image rectangle.

函式 cv::clipLine 計算完全位於指定矩形內的線段部分。如果線段完全在矩形外部,則返回 false。否則,返回 true。

引數
imgSize影像尺寸。影像矩形為 Rect(0, 0, imgSize.width, imgSize.height)。
pt1線的第一個點。
pt2線的第二個點。

◆ clipLine() [3/3]

bool cv::clipLine ( Size2l imgSize,
Point2l & pt1,
Point2l & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

引數
imgSize影像尺寸。影像矩形為 Rect(0, 0, imgSize.width, imgSize.height)。
pt1線的第一個點。
pt2線的第二個點。

◆ drawContours()

void cv::drawContours ( InputOutputArray image,
InputArrayOfArrays contours,
int contourIdx,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
InputArray hierarchy = noArray(),
int maxLevel = INT_MAX,
Point offset = Point() )
Python
cv.drawContours(image, contours, contourIdx, color[, thickness[, lineType[, hierarchy[, maxLevel[, offset]]]]]) -> image

#include <opencv2/imgproc.hpp>

繪製輪廓線或填充輪廓。

如果 \(\texttt{thickness} \ge 0\) 則函式在影像中繪製輪廓線,如果 \(\texttt{thickness}<0\) 則填充輪廓所限定的區域。下面的示例展示瞭如何從二值影像中檢索連通分量並對其進行標記:

using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat src;
// 第一個命令列引數必須是二值影像的檔名
// (黑白)影像
if( argc != 2 || !(src=imread(argv[1], IMREAD_GRAYSCALE)).data)
return -1;
Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
src = src > 1;
namedWindow( "Source", 1 );
imshow( "Source", src );
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( src, contours, hierarchy,
RETR_CCOMP, CHAIN_APPROX_SIMPLE );
// 迭代所有頂層輪廓,
// 用其自己的隨機顏色繪製每個連線的元件
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
Scalar color( rand()&255, rand()&255, rand()&255 );
drawContours( dst, contours, idx, color, FILLED, 8, hierarchy );
}
namedWindow( "Components", 1 );
imshow( "Components", dst );
waitKey(0);
}
n 維密集陣列類
定義 mat.hpp:830
int cols
定義 mat.hpp:2165
int rows
當矩陣維度大於2時,行數和列數,或(-1, -1)
定義 mat.hpp:2165
CV_8UC3
#define CV_8UC3
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
建立視窗。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
從檔案載入影像。
void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
繪製輪廓線或填充輪廓。
void findContours(InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
在二值影像中查詢輪廓。
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3
定義 core.hpp:107
STL 名稱空間。
引數
image目標影像。
contours所有輸入輪廓。每個輪廓都儲存為一個點向量。
contourIdx指示要繪製的輪廓的引數。如果為負,則繪製所有輪廓。
color輪廓的顏色。
thickness繪製輪廓線的粗細。如果為負(例如,thickness=FILLED),則繪製輪廓內部。
lineType線條連線性。參見 LineTypes
hierarchy可選的層次結構資訊。僅當您只想繪製部分輪廓時才需要(參見 maxLevel)。
maxLevel繪製輪廓的最大級別。如果為0,則僅繪製指定的輪廓。如果為1,則函式繪製輪廓及其所有巢狀輪廓。如果為2,則函式繪製輪廓、所有巢狀輪廓、所有巢狀的巢狀輪廓,依此類推。此引數僅在存在層次結構時才考慮。
offset可選的輪廓偏移引數。將所有繪製的輪廓按指定的 \(\texttt{offset}=(dx,dy)\) 偏移。
注意
當 thickness=FILLED 時,即使沒有提供層次結構資料,該函式也能正確處理帶孔的連通分量。這是透過使用奇偶規則一起分析所有輪廓來完成的。如果您有一個單獨檢索的輪廓的聯合集合,這可能會產生不正確的結果。為了解決這個問題,您需要為每個輪廓子組分別呼叫 drawContours,或使用 contourIdx 引數遍歷集合。

◆ drawMarker()

void cv::drawMarker ( InputOutputArray img,
Point position,
const Scalar & color,
int markerType = MARKER_CROSS,
int markerSize = 20,
int thickness = 1,
int line_type = 8 )
Python
cv.drawMarker(img, position, color[, markerType[, markerSize[, thickness[, line_type]]]]) -> img

#include <opencv2/imgproc.hpp>

在影像中的預定義位置繪製標記。

函式 cv::drawMarker 在影像中的給定位置繪製標記。目前支援幾種標記型別,詳見 MarkerTypes

引數
img影像。
position十字標記的定位點。
coloropencv2/ximgproc/fast_line_detector.hpp
markerType你想要使用的標記的具體型別,參見 MarkerTypes
thicknessLine thickness.
line_type線的型別,參見 LineTypes
markerSize標記軸的長度 [預設 = 20 畫素]

◆ ellipse() [1/2]

void cv::ellipse ( InputOutputArray img,
const RotatedRect & box,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8 )
Python
cv.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]]) -> img
cv.ellipse(img, box, color[, thickness[, lineType]]) -> img

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

引數
img影像。
box透過 RotatedRect 的另一種橢圓表示形式。這意味著此函式繪製一個內切於旋轉矩形的橢圓。
color橢圓顏色。
thickness橢圓弧輪廓的粗細,如果為正。否則,表示將繪製一個填充的橢圓扇區。
lineType橢圓邊界的型別。參見 LineTypes

◆ ellipse() [2/2]

void cv::ellipse ( InputOutputArray img,
Point center,
Size axes,
double angle,
double startAngle,
double endAngle,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]]) -> img
cv.ellipse(img, box, color[, thickness[, lineType]]) -> img

#include <opencv2/imgproc.hpp>

繪製簡單或粗橢圓弧或填充橢圓扇區。

具有更多引數的函式 cv::ellipse 繪製橢圓輪廓、填充橢圓、橢圓弧或填充橢圓扇區。繪圖程式碼使用一般引數形式。分段線性曲線用於近似橢圓弧邊界。如果您需要對橢圓渲染進行更多控制,可以使用 ellipse2Poly 獲取曲線,然後使用 polylines 渲染或使用 fillPoly 填充。如果您使用函式的第一個變體並想要繪製整個橢圓而不是弧,請傳遞 startAngle=0endAngle=360。如果 startAngle 大於 endAngle,它們將被交換。下圖解釋了繪製藍色弧線的引數含義。

橢圓弧的引數
引數
img影像。
center橢圓中心。
axes橢圓主軸尺寸的一半。
angle橢圓旋轉角度(以度為單位)。
startAngle橢圓弧的起始角度(以度為單位)。
endAngle橢圓弧的結束角度(以度為單位)。
color橢圓顏色。
thickness橢圓弧輪廓的粗細,如果為正。否則,表示將繪製一個填充的橢圓扇區。
lineType橢圓邊界的型別。參見 LineTypes
移位 (shift)中心座標和軸值中的小數位數。

◆ ellipse2Poly() [1/2]

void cv::ellipse2Poly ( Point center,
Size axes,
int angle,
int arcStart,
int arcEnd,
int delta,
std::vector< Point > & pts )
Python
cv.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta) -> pts

#include <opencv2/imgproc.hpp>

用多邊形逼近橢圓弧。

函式 ellipse2Poly 計算近似指定橢圓弧的折線頂點。它被 ellipse 使用。如果 arcStart 大於 arcEnd,它們將被交換。

引數
center弧的中心。
axes橢圓主軸尺寸的一半。詳見 ellipse
angle橢圓的旋轉角度(以度為單位)。詳見 ellipse
arcStart橢圓弧的起始角度(以度為單位)。
arcEnd橢圓弧的結束角度(以度為單位)。
delta連續折線頂點之間的角度。它定義了近似精度。
pts折線頂點的輸出向量。

◆ ellipse2Poly() [2/2]

void cv::ellipse2Poly ( Point2d center,
Size2d axes,
int angle,
int arcStart,
int arcEnd,
int delta,
std::vector< Point2d > & pts )
Python
cv.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta) -> pts

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

引數
center弧的中心。
axes橢圓主軸尺寸的一半。詳見 ellipse
angle橢圓的旋轉角度(以度為單位)。詳見 ellipse
arcStart橢圓弧的起始角度(以度為單位)。
arcEnd橢圓弧的結束角度(以度為單位)。
delta連續折線頂點之間的角度。它定義了近似精度。
pts折線頂點的輸出向量。

◆ fillConvexPoly() [1/2]

void cv::fillConvexPoly ( InputOutputArray img,
const Point * pts,
int npts,
const Scalar & color,
int lineType = LINE_8,
int shift = 0 )
Python
cv.fillConvexPoly(img, points, color[, lineType[, shift]]) -> img

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

◆ fillConvexPoly() [2/2]

void cv::fillConvexPoly ( InputOutputArray img,
InputArray points,
const Scalar & color,
int lineType = LINE_8,
int shift = 0 )
Python
cv.fillConvexPoly(img, points, color[, lineType[, shift]]) -> img

#include <opencv2/imgproc.hpp>

填充凸多邊形。

函式 cv::fillConvexPoly 繪製一個填充的凸多邊形。此函式比函式 fillPoly 快得多。它不僅可以填充凸多邊形,還可以填充任何沒有自相交的單調多邊形,即其輪廓最多與每條水平線(掃描線)相交兩次的多邊形(儘管其最頂部和/或最底部邊緣可以是水平的)。

引數
img影像。
points多邊形頂點。
color多邊形顏色。
lineType多邊形邊界的型別。參見 LineTypes
移位 (shift)頂點座標中的小數位數。

◆ fillPoly() [1/2]

void cv::fillPoly ( InputOutputArray img,
const Point ** pts,
const int * npts,
int ncontours,
const Scalar & color,
int lineType = LINE_8,
int shift = 0,
Point offset = Point() )
Python
cv.fillPoly(img, pts, color[, lineType[, shift[, offset]]]) -> img

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

◆ fillPoly() [2/2]

void cv::fillPoly ( InputOutputArray img,
InputArrayOfArrays pts,
const Scalar & color,
int lineType = LINE_8,
int shift = 0,
Point offset = Point() )
Python
cv.fillPoly(img, pts, color[, lineType[, shift[, offset]]]) -> img

#include <opencv2/imgproc.hpp>

填充一個或多個多邊形所包圍的區域。

函式 cv::fillPoly 填充由多個多邊形輪廓圍成的區域。該函式可以填充複雜的區域,例如帶有孔洞的區域、具有自相交的輪廓(某些部分)等等。

引數
img影像。
pts多邊形陣列,其中每個多邊形表示為點陣列。
color多邊形顏色。
lineType多邊形邊界的型別。參見 LineTypes
移位 (shift)頂點座標中的小數位數。
offset輪廓所有點的可選偏移量。

◆ getFontScaleFromHeight()

double cv::getFontScaleFromHeight ( const int fontFace,
const int pixelHeight,
const int thickness = 1 )
Python
cv.getFontScaleFromHeight(fontFace, pixelHeight[, thickness]) -> retval

#include <opencv2/imgproc.hpp>

計算用於達到給定畫素高度的字型特定大小。

引數
fontFace要使用的字型,參見 cv::HersheyFonts
pixelHeight用於計算 fontScale 的畫素高度
thickness用於渲染文字的線條粗細。詳見 putText。
返回
用於 cv::putText 的字型大小
另請參見
cv::putText

◆ getTextSize()

Size cv::getTextSize ( const String & text,
int fontFace,
double fontScale,
int thickness,
int * baseLine )
Python
cv.getTextSize(text, fontFace, fontScale, thickness) -> retval, baseLine

#include <opencv2/imgproc.hpp>

計算文字字串的寬度和高度。

函式 cv::getTextSize 計算並返回包含指定文字的框的大小。也就是說,以下程式碼渲染文字、圍繞文字的緊密框以及基線:

String text = "Funny text inside the box";
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);
static Scalar_< double > all(double v0)
用於指定影像或矩形大小的模板類。
Definition types.hpp:335
_Tp height
高度
Definition types.hpp:363
_Tp width
寬度
Definition types.hpp:362
typedef Point_< double > 
Point2i Point
Definition types.hpp:209
std::string String
定義 cvstd.hpp:151
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製一個簡單、粗或填充的矩形。
Size getTextSize(const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
計算文字字串的寬度和高度。
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
繪製文字字串。
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
繪製連線兩點的線段。
@ FONT_HERSHEY_SCRIPT_SIMPLEX
手寫風格字型
定義 imgproc.hpp:909
引數
text輸入文字字串。
fontFace要使用的字型,參見 HersheyFonts
fontScale字型縮放因子,乘以字型特有的基本大小。
thickness用於渲染文字的線條粗細。詳見 putText
[輸出]baseLine基線相對於文字最底點的 y 座標。
返回
包含指定文字的框的大小。
另請參見
putText

◆ line()

void cv::line ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

繪製連線兩點的線段。

函式 line 在影像中繪製 pt1 和 pt2 點之間的線段。線段被影像邊界裁剪。對於具有整數座標的非抗鋸齒線條,使用 8 連通或 4 連通的 Bresenham 演算法。粗線以圓角端點繪製。抗鋸齒線條使用高斯濾波繪製。

引數
img影像。
pt1線段的第一個點。
pt2線段的第二個點。
coloropencv2/ximgproc/fast_line_detector.hpp
thicknessLine thickness.
lineType線的型別。參見 LineTypes
移位 (shift)點座標中的小數位數。

◆ polylines() [1/2]

void cv::polylines ( InputOutputArray img,
const Point *const * pts,
const int * npts,
int ncontours,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

◆ polylines() [2/2]

void cv::polylines ( InputOutputArray img,
InputArrayOfArrays pts,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

繪製多條多邊形曲線。

引數
img影像。
pts多邊形曲線陣列。
isClosed指示繪製的多段線是否閉合的標誌。如果閉合,函式將從每條曲線的最後一個頂點到其第一個頂點繪製一條線。
color多段線顏色。
thickness多段線邊緣的粗細。
lineType線段的型別。參見 LineTypes
移位 (shift)頂點座標中的小數位數。

函式 cv::polylines 繪製一個或多個多邊形曲線。

◆ putText()

void cv::putText ( InputOutputArray img,
const String & text,
Point org,
int fontFace,
double fontScale,
Scalar color,
int thickness = 1,
int lineType = LINE_8,
bool bottomLeftOrigin = false )
Python
cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) -> img

#include <opencv2/imgproc.hpp>

繪製文字字串。

函式 cv::putText 在影像中渲染指定的文字字串。無法使用指定字型渲染的符號將替換為問號。有關文字渲染程式碼示例,請參見 getTextSize

fontScale 引數是一個縮放因子,它乘以基本字型大小

  • 當 scale > 1 時,文字被放大。
  • 當 0 < scale < 1 時,文字被縮小。
  • 當 scale < 0 時,文字被映象或反轉。
引數
img影像。
text要繪製的文字字串。
org影像中文字字串的左下角。
fontFace字型型別,參見 HersheyFonts
fontScale字型縮放因子,乘以字型特有的基本大小。
color文字顏色。
thickness用於繪製文字的線條粗細。
lineType線條型別。參見 LineTypes
bottomLeftOrigin當為 true 時,影像資料原點在左下角。否則,在左上角。
示例
samples/cpp/fitellipse.cpp.

◆ rectangle() [1/2]

void cv::rectangle ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) -> img
cv.rectangle(img, rec, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

繪製一個簡單、粗或填充的矩形。

函式 cv::rectangle 繪製矩形輪廓或填充矩形,其兩個相對角為 pt1 和 pt2。

引數
img影像。
pt1矩形的頂點。
pt2與 pt1 相對的矩形頂點。
color矩形顏色或亮度(灰度影像)。
thickness構成矩形的線條粗細。負值(例如 FILLED)表示函式需要繪製一個填充矩形。
lineType線條型別。參見 LineTypes
移位 (shift)點座標中的小數位數。

◆ rectangle() [2/2]

void cv::rectangle ( InputOutputArray img,
Rect rec,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) -> img
cv.rectangle(img, rec, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

這是一個過載成員函式,為方便起見而提供。它與上述函式的區別僅在於所接受的引數。

使用 rec 引數作為繪製矩形的替代規範:r.tl()r.br()-Point(1,1) 是相對角