OpenCV 4.13.0
開源計算機視覺庫 (Open Source Computer Vision)
正在載入...
正在搜尋...
未找到匹配項
繪圖函式

詳細說明

繪圖函式適用於任意深度的矩陣/影像。形狀的邊界可以渲染抗鋸齒(目前僅針對8點陣圖像實現)。所有函式都包含引數 color,對於彩色影像,它使用 RGB 值(可以使用 Scalar 建構函式構建),對於灰度影像,它使用亮度值。對於彩色影像,通道順序通常是 Blue, Green, Red。這也是 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)
 

列舉

enum  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
}
 
enum  cv::LineTypes {
  cv::FILLED = -1 ,
  cv::LINE_4 = 4 ,
  cv::LINE_8 = 8 ,
  cv::LINE_AA = 16
}
 
enum  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)
 繪製一個圓。
 
bool cv::clipLine (Rect imgRect, Point &pt1, Point &pt2)
 
bool cv::clipLine (Size imgSize, Point &pt1, Point &pt2)
 根據影像矩形裁剪直線。
 
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]

列舉型別文件 (Enumeration Type Documentation)

◆ HersheyFonts

#include <opencv2/imgproc.hpp>

只支援 Hershey 字型 https://en.wikipedia.org/wiki/Hershey_fonts 的子集

列舉值 (Enumerator)
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>

線條型別

列舉值 (Enumerator)
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 函式的標記型別集合

列舉值 (Enumerator)
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

向下指向的三角形標記。

函式文件 (Function Documentation)

◆ 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箭頭的指向點。
color線條顏色。
thickness線條粗細。
line_type線條型別。參見 LineTypes
移位點座標中的小數位數。
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>

繪製一個圓。

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

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

◆ 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 影像尺寸,
點 (Point) & pt1,
點 (Point) & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

根據影像矩形裁剪直線。

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

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

◆ clipLine() [3/3]

bool cv::clipLine ( Size2l 影像尺寸,
Point2l & pt1,
Point2l & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

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

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

◆ drawContours()

void cv::drawContours ( InputOutputArray 影像,
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]]]]]) -> 影像

#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;
// 第一個命令列引數必須是二值(黑白)影像的檔名
// (black-n-white) image
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:840
int cols
定義 mat.hpp:2204
int rows
行數和列數,當矩陣超過 2 維時為 (-1, -1)
定義 mat.hpp:2204
#define CV_8UC3
定義於 interface.h:90
void imshow(const String &winname, InputArray mat)
在指定視窗中顯示影像。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
建立視窗。
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 名稱空間。
引數
影像目標影像。
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十字線標記的位置。
color線條顏色。
markerType您想要使用的特定標記型別,參見 MarkerTypes
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
移位中心座標和軸值中的小數位數。

◆ 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
移位頂點座標中的小數位數。

◆ 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
移位頂點座標中的小數位數。
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;
// 居中文字
Point textOrg((img.cols - textSize.width)/2,
(img.rows + textSize.height)/2);
// 繪製框
rectangle(img, textOrg + Point(0, baseline),
textOrg + Point(textSize.width, -textSize.height),
Scalar(0,0,255));
// ... 先繪製基線
line(img, textOrg + Point(0, thickness),
textOrg + Point(textSize.width, thickness),
Scalar(0, 0, 255));
// 然後放置文字本身
putText(img, text, textOrg, fontFace, fontScale,
Scalar::all(255), thickness, 8);
static Scalar_< double > all(double v0)
用於指定影像或矩形大小的模板類。
定義 types.hpp:335
_Tp height (高度)
高度
定義 types.hpp:363
_Tp width (寬度)
寬度
定義 types.hpp:362
Point2i Point
定義於 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
手寫體風格字型
Definition imgproc.hpp:913
引數
text輸入文字字串。
fontFace要使用的字型,參見 HersheyFonts
fontScale字型縮放因子,乘以字型特定的基本大小。
thickness用於渲染文字的線條粗細。詳情參見 putText
[out]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線段的第二個點。
color線條顏色。
thickness線條粗細。
lineType線條型別。參見 LineTypes
移位點座標中的小數位數。

◆ 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
移位頂點座標中的小數位數。

函式 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
移位點座標中的小數位數。

◆ 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() and r.br()-Point(1,1) 是對角。