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

詳細描述

image

此圖解釋了使用 Qt* GUI 實現的新功能。新的 GUI 提供了一個狀態列、一個工具欄和一個控制面板。控制面板可以附帶跟蹤條和按鈕條。如果您看不到控制面板,請按 Ctrl+P 或右鍵單擊任何 Qt 視窗並選擇顯示屬性視窗

請參見下方用於生成該圖的示例

int main(int argc, char *argv[])
{
int value = 50;
int value2 = 0;
namedWindow("main1",WINDOW_NORMAL);
namedWindow("main2",WINDOW_AUTOSIZE | WINDOW_GUI_NORMAL);
createTrackbar( "track1", "main1", &value, 255, NULL);
String nameb1 = "button1";
String nameb2 = "button2";
createButton(nameb1,callbackButton,&nameb1,QT_CHECKBOX,1);
createButton(nameb2,callbackButton,NULL,QT_CHECKBOX,0);
createTrackbar( "track2", NULL, &value2, 255, NULL);
createButton("button5",callbackButton1,NULL,QT_RADIOBOX,0);
createButton("button6",callbackButton2,NULL,QT_RADIOBOX,1);
setMouseCallback( "main2",on_mouse,NULL );
Mat img1 = imread("files/flower.jpg");
VideoCapture video;
video.open("files/hockey.avi");
Mat img2,img3;
while( waitKey(33) != 27 )
{
img1.convertTo(img2,-1,1,value);
video >> img3;
imshow("main1",img2);
imshow("main2",img3);
}
destroyAllWindows();
return 0;
}
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3

結構體  cv::QtFont
 QtFont 僅適用於 Qt。參見 cv::fontQt更多...
 

列舉

列舉  cv::QtButtonTypes {
  cv::QT_PUSH_BUTTON = 0 ,
  cv::QT_CHECKBOX = 1 ,
  cv::QT_RADIOBOX = 2 ,
  cv::QT_NEW_BUTTONBAR = 1024
}
 Qt “按鈕”型別。更多...
 
列舉  cv::QtFontStyles {
  cv::QT_STYLE_NORMAL = 0 ,
  cv::QT_STYLE_ITALIC = 1 ,
  cv::QT_STYLE_OBLIQUE = 2
}
 Qt 字型樣式。更多...
 
列舉  cv::QtFontWeights {
  cv::QT_FONT_LIGHT = 25 ,
  cv::QT_FONT_NORMAL = 50 ,
  cv::QT_FONT_DEMIBOLD = 63 ,
  cv::QT_FONT_BOLD = 75 ,
  cv::QT_FONT_BLACK = 87
}
 Qt 字型粗細。更多...
 

函式

void cv::addText (const Mat &img, const String &text, Point org, const QtFont &font)
 在影像上繪製文字。
 
void cv::addText (const Mat &img, const String &text, Point org, const String &nameFont, int pointSize=-1, Scalar color=Scalar::all(0), int weight=QT_FONT_NORMAL, int style=QT_STYLE_NORMAL, int spacing=0)
 在影像上繪製文字。
 
int cv::createButton (const String &bar_name, ButtonCallback on_change, void *userdata=0, int type=QT_PUSH_BUTTON, bool initial_button_state=false)
 Attaches a button to the control panel.
 
void cv::displayOverlay (const String &winname, const String &text, int delayms=0)
 在視窗影像上以疊加層形式顯示文字,持續指定時間。
 
void cv::displayStatusBar (const String &winname, const String &text, int delayms=0)
 在指定時間內在視窗狀態列上顯示文字。
 
QtFont cv::fontQt (const String &nameFont, int pointSize=-1, Scalar color=Scalar::all(0), int weight=QT_FONT_NORMAL, int style=QT_STYLE_NORMAL, int spacing=0)
 建立用於在影像上繪製文字的字型。
 
void cv::loadWindowParameters (const String &windowName)
 載入指定視窗的引數。
 
void cv::saveWindowParameters (const String &windowName)
 儲存指定視窗的引數。
 
int cv::startLoop (int(*pt2Func)(int argc, char *argv[]), int argc, char *argv[])
 
void cv::stopLoop ()
 

列舉型別文件

◆ QtButtonTypes

#include <opencv2/highgui.hpp>

Qt “按鈕”型別。

列舉器
QT_PUSH_BUTTON 
Python: cv.QT_PUSH_BUTTON

按鈕。

QT_CHECKBOX 
Python: cv.QT_CHECKBOX

複選框按鈕。

QT_RADIOBOX 
Python: cv.QT_RADIOBOX

單選框按鈕。

QT_NEW_BUTTONBAR 
Python: cv.QT_NEW_BUTTONBAR

按鈕應建立一個新的按鈕條。

◆ QtFontStyles

#include <opencv2/highgui.hpp>

Qt 字型樣式。

列舉器
QT_STYLE_NORMAL 
Python: cv.QT_STYLE_NORMAL

普通字型。

QT_STYLE_ITALIC 
Python: cv.QT_STYLE_ITALIC

斜體字型。

QT_STYLE_OBLIQUE 
Python: cv.QT_STYLE_OBLIQUE

傾斜字型。

◆ QtFontWeights

#include <opencv2/highgui.hpp>

Qt 字型粗細。

列舉器
QT_FONT_LIGHT 
Python: cv.QT_FONT_LIGHT

粗細為 25。

QT_FONT_NORMAL 
Python: cv.QT_FONT_NORMAL

粗細為 50。

QT_FONT_DEMIBOLD 
Python: cv.QT_FONT_DEMIBOLD

粗細為 63。

QT_FONT_BOLD 
Python: cv.QT_FONT_BOLD

粗細為 75。

QT_FONT_BLACK 
Python: cv.QT_FONT_BLACK

粗細為 87。

函式文件

◆ addText() [1/2]

void cv::addText ( const Mat & img,
const String & text,
Point org,
const QtFont & font )
Python
cv.addText(img, text, org, nameFont[, pointSize[, color[, weight[, style[, spacing]]]]]) ->

#include <opencv2/highgui.hpp>

在影像上繪製文字。

函式 addText 使用特定字型 font(參見示例 cv::fontQt)在影像 img 上繪製文字

引數
img應繪製文字的 8 位 3 通道影像。
text要寫入影像的文字。
orgPoint(x,y) 文字應在影像上開始的位置。
字型用於繪製文字的字型。

◆ addText() [2/2]

void cv::addText ( const Mat & img,
const String & text,
Point org,
const String & nameFont,
int pointSize = -1,
Scalar color = Scalar::all(0),
int weight = QT_FONT_NORMAL,
int style = QT_STYLE_NORMAL,
int spacing = 0 )
Python
cv.addText(img, text, org, nameFont[, pointSize[, color[, weight[, style[, spacing]]]]]) ->

#include <opencv2/highgui.hpp>

在影像上繪製文字。

引數
img應繪製文字的 8 位 3 通道影像。
text要寫入影像的文字。
orgPoint(x,y) 文字應在影像上開始的位置。
nameFont字型的名稱。名稱應與系統字型(如 Times*)的名稱匹配。如果未找到字型,則使用預設字型。
pointSize字型大小。如果未指定、等於零或為負,則字型磅值將設定為系統相關的預設值。通常為 12 磅。
colorBGRA 格式的字型顏色,其中 A = 255 表示完全透明。
weight字型粗細。可用操作標誌為:cv::QtFontWeights 您也可以指定一個正整數以進行更好的控制。
樣式字型樣式。可用操作標誌為:cv::QtFontStyles
間距字元之間的間距。可以是負數或正數。

◆ createButton()

int cv::createButton ( const String & bar_name,
ButtonCallback on_change,
void * userdata = 0,
int type = QT_PUSH_BUTTON,
bool initial_button_state = false )

#include <opencv2/highgui.hpp>

Attaches a button to the control panel.

函式 createButton 將一個按鈕附加到控制面板。每個按鈕都新增到上一個按鈕右側的按鈕條中。如果沒有事先附加任何內容到控制面板,或者如果附加到控制面板的最後一個元素是跟蹤條,或者如果 QT_NEW_BUTTONBAR 標誌被新增到型別中,則會建立一個新的按鈕條。

下面是 cv::createButton 函式呼叫的各種示例:

createButton("",callbackButton);//建立一個名為“button 0”的按鈕,它將呼叫 callbackButton。
createButton("button2",callbackButton,NULL,QT_CHECKBOX,0);
createButton("button3",callbackButton,&value);
createButton("button5",callbackButton1,NULL,QT_RADIOBOX);
createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON,1);
createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON|QT_NEW_BUTTONBAR);//在新行中建立一個按鈕
int createButton(const String &bar_name, ButtonCallback on_change, void *userdata=0, int type=QT_PUSH_BUTTON, bool initial_button_state=false)
Attaches a button to the control panel.
@ QT_CHECKBOX
複選框按鈕。
定義 highgui.hpp:215
@ QT_RADIOBOX
單選框按鈕。
定義 highgui.hpp:216
@ QT_PUSH_BUTTON
按鈕。
定義 highgui.hpp:214
@ QT_NEW_BUTTONBAR
按鈕應建立一個新的按鈕條。
定義 highgui.hpp:217
引數
bar_name按鈕名稱。
on_change指向每次按鈕狀態改變時要呼叫的函式的指標。該函式應原型為 void Foo(int state,*void);。state 是按鈕的當前狀態。對於按鈕,它可以是 -1,對於複選框/單選框,可以是 0 或 1。
使用者資料傳遞給回撥函式的指標。
type按鈕的可選型別。可用型別為:(cv::QtButtonTypes)
initial_button_state按鈕的預設狀態。用於複選框和單選框。其值可以是 0 或 1。(可選

◆ displayOverlay()

void cv::displayOverlay ( const String & 視窗名稱,
const String & text,
int delayms = 0 )
Python
cv.displayOverlay(winname, text[, delayms]) ->

#include <opencv2/highgui.hpp>

在視窗影像上以疊加層形式顯示文字,持續指定時間。

函式 displayOverlay 在視窗頂部顯示有用的資訊/提示,持續指定時間 delayms。該函式不修改視窗中顯示的影像,即在指定延遲後,視窗的原始內容將恢復。

引數
視窗名稱視窗名稱。
text要寫入視窗影像的疊加文字。
delayms疊加文字顯示的時長(毫秒)。如果在上一個疊加文字超時之前呼叫此函式,則計時器將重新啟動並更新文字。如果此值為零,則文字永不消失。

◆ displayStatusBar()

void cv::displayStatusBar ( const String & 視窗名稱,
const String & text,
int delayms = 0 )
Python
cv.displayStatusBar(winname, text[, delayms]) ->

#include <opencv2/highgui.hpp>

在指定時間內在視窗狀態列上顯示文字。

函式 displayStatusBar 在視窗頂部顯示有用的資訊/提示,持續指定時間 delayms。此資訊顯示在視窗狀態列上(視窗必須使用 CV_GUI_EXPANDED 標誌建立)。

引數
視窗名稱視窗名稱。
text要寫入視窗狀態列的文字。
delayms顯示文字的時長(毫秒)。如果在上一個文字超時之前呼叫此函式,則計時器將重新啟動並更新文字。如果此值為零,則文字永不消失。

◆ fontQt()

QtFont cv::fontQt ( const String & nameFont,
int pointSize = -1,
Scalar color = Scalar::all(0),
int weight = QT_FONT_NORMAL,
int style = QT_STYLE_NORMAL,
int spacing = 0 )

#include <opencv2/highgui.hpp>

建立用於在影像上繪製文字的字型。

函式 fontQt 建立一個 cv::QtFont 物件。此 cv::QtFont 與 putText 不相容。

此函式的基本用法如下:

QtFont font = fontQt("Times");
addText( img1, "Hello World !", Point(50,50), font);
typedef Point_< double > 
Point2i Point
Definition types.hpp:209
void addText(const Mat &img, const String &text, Point org, const QtFont &font)
在影像上繪製文字。
QtFont fontQt(const String &nameFont, int pointSize=-1, Scalar color=Scalar::all(0), int weight=QT_FONT_NORMAL, int style=QT_STYLE_NORMAL, int spacing=0)
建立用於在影像上繪製文字的字型。
QtFont 僅適用於 Qt。參見 cv::fontQt。
定義 highgui.hpp:677
引數
nameFont字型的名稱。名稱應與系統字型(如 Times*)的名稱匹配。如果未找到字型,則使用預設字型。
pointSize字型大小。如果未指定、等於零或為負,則字型磅值將設定為系統相關的預設值。通常為 12 磅。
colorBGRA 格式的字型顏色,其中 A = 255 表示完全透明。為簡單起見,請使用宏 CV_RGB。
weight字型粗細。可用操作標誌為:cv::QtFontWeights 您也可以指定一個正整數以進行更好的控制。
樣式字型樣式。可用操作標誌為:cv::QtFontStyles
間距字元之間的間距。可以是負數或正數。

◆ loadWindowParameters()

void cv::loadWindowParameters ( const String & 視窗名稱)

#include <opencv2/highgui.hpp>

載入指定視窗的引數。

函式 loadWindowParameters 載入視窗 windowName 的大小、位置、標誌、跟蹤條值、縮放和平移位置。

引數
視窗名稱視窗名稱。

◆ saveWindowParameters()

void cv::saveWindowParameters ( const String & 視窗名稱)

#include <opencv2/highgui.hpp>

儲存指定視窗的引數。

函式 saveWindowParameters 儲存視窗 windowName 的大小、位置、標誌、跟蹤條值、縮放和平移位置。

引數
視窗名稱視窗名稱。

◆ startLoop()

int cv::startLoop ( int(* pt2Func )(int argc, char *argv[]),
int argc,
char * argv[] )

#include <opencv2/highgui.hpp>

◆ stopLoop()

void cv::stopLoop ( )

#include <opencv2/highgui.hpp>