当前位置:网站首页>Introduction to QT: video player
Introduction to QT: video player
2022-07-08 02:16:00 【Strawberry sauce toast】
Recently, due to engineering needs , Begin to learn QT Programming .
Two points learned in this process :
- The program is not simply stacked , Be sure to understand the role of every sentence you write ;
- Careful and patient , look for bug It's a great waste of patience , So think about it before you start .
This article introduces you to use QT The process of implementing a simple video player , Introduce some entry-level knowledge points encountered in this process , And the solution .
introduction
1. QT Of “ Cross platform ” characteristic
I only knew QT It's cross platform , But yes. “ platform ” Your understanding is not accurate .
When we talk about developing applications , Platform may have many different meanings , Including operating system type 、 Operating system version 、 Compiler type 、 Compiler version and processor architecture (32 position 、64 position 、ARM etc. ).
QT frame : Open source application development framework widely used to create rich visual effects , You can build and compile between different platforms , And hardly need to change any line of code , But the premise is that no non QT Or platform specific libraries .(e.g. stay Windows The next program , If used windows The library of , You cannot migrate directly to ARM The use of .)
2. QT Supported compilers
MSVC , MinGW, GCC
3. OpenCV brief introduction
OpenCV It's open source 、 Cross platform library , For developing computer vision applications , Focus on speed and performance , It can be divided into main module and additional module .
OpenCV The main module :
- Core functions (core modular ), Included by all others OpenCV All basic structures used by the module 、 Constants and functions ,(e.g. Mat class );
- The image processing (imgproc modular ), Including image filtering 、 Different algorithms of image transformation ,(e.g. median, mean,......);
- Two dimensional feature frame module (feature2d), Contains classes and methods for feature extraction and matching ;(e.g. SURF, SIFT,......)
- Video module , Contains for motion estimation 、 Algorithms for background subtraction, tracking and other topics .
4. How to be in QT Of .pro Configuration in file OpenCV?
First , You need to select any folder ( Usually choose to build OpenCV Folder , To ensure that all are related to OpenCV All relevant files are in the same folder ), Create a folder named “opencv.pri” Text file for ;
Windows user
(1) stay opencv.pri Enter the following in the file :
INCLUDEPATH += C:/opencv/build/install/include
Debug:{
LIBS += -LC:/opencv/build/install/x64/vc16/lib/opencv_world330d
}
Release:{
LIBS += -LC:/opencv/build/install/x64/vc16/lib/opencv_world330
}
(2) take OpenCV Of DLL Add folder to system Path route ,DLL Folder location :C:/opencv/build/install/x64/vc16/bin
Macos/Linux user
stay opencv.pri Add the following to the file , There is no need to configure the path
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib \
-lopencv_world
To configure .pro file
stay .pro Add at the end of the file :
include(C:/opencv/opencv.pri)
One 、 Interface layout
At first, I was in a state of confusion , Several projects have been established , Decide to build the interface first and then write the code . This process really breaks through itself “ be anxious for success ” Mentality and habits , I feel that learning programming is really like wild fungus , Learning in scattered ways is not enough to get started , So this semester always falls into ” How can I do this “ In self doubt ( I must have written too little to make this kind of critical hit more violent )
The final interface is shown in the figure 1
- Use QLabel Control displays an image
- Contains the selection file , Start 、 Pause play , Forward 、 back off , Display current progress and total length of video ;
- Save function : Save a single frame , Save a video ;
- Display adjustment : brightness 、 Contrast adjustment ; Enlarge the display and display the original size .
chart 1 Video player layout and functions to be realized
Two 、 Open file
The mode selected here is : Click on “ Open file ”, eject “ File selection dialog ”, The function used is :
https://blog.csdn.net/liyj127/article/details/54090705
QString filename = QFileDialog::getOpenFileName(this, "Open Input File",
QDir::currentPath(), "FileType (*.jpg *png *.bmp)");
if (QFile::exists(filename))
{
……
}
QString turn char*
QString str;
char* ch;
QByteArray ba = str.toLatin1(); // must
ch=ba.data();
3、 ... and 、QLabel Display images
The trouble with this step is that the author reads pixel values byte by byte from the file , And the value needs to be grayscale mapped and displayed as 8bit grayscale .
- Used to store 16-bit And 8-bit The data types of pixel values of are selected as unsigned short And unsigned char;
- To use QLable The display image needs data type conversion :unsigned char---> QImage---> QPixmap;
unsigned char Array rotation QImage
QImage qimg = QImage(&ch[0], img_width, img_height, m_width, QImage::Format_Grayscale8);
The first parameter is zero char Array address ; second 、 The three parameters are the width and height of the image ; The fourth parameter is the number of bytes per line of the image ; The fifth parameter refers to QImage Format Introduction .
QLable Display images
// Display image size and QLabel Same size
ui->ImageLabel->setPixmap(QPixmap::fromImage(qimg).scaled(ui->ImageLabel->size()));
// Display the size of the original image
ui->ImageLabel->setPixmap(QPixmap::fromImage(qimg));
// QImage turn QPixmap
QPixmap pixmap = QPixmap::fromImage(qimg);
Four 、 Refresh the interface
Interface refresh use QTimer class
// establish QTimer object
QTimer* qtimer = new QTimer(this);
// Set refresh rate
qtimer->start(200); // Every time 200ms Refresh once
// perhaps
qTimer->setInterval(200);
qTimer->start();
// Judge timer The state of
qtimer->isActive(); // true -- Start refreshing ;false -- Stop refreshing
// Stop refreshing
qtimer->stop();
// binding update() function
connect(qtimer, SIGNAL(timerout()), this, SLOT(update()));
update() The function can be replaced by a custom slot function , But this function should include update() function .
5、 ... and 、 some Bug
1. Right click the control to automatically create a slot function , After the slot function is deleted ,moc_..... File compilation error
Solution : Not only in .cpp Delete the definition of slot function in the file , Also delete .h File slot function declaration and rebuild the project , Otherwise, an error will be reported when building the project .
2. Custom slot function
The custom slot function must be declared in private slots: below , For example, customized and timer Bound slot function
Otherwise connect It won't work !
3. Use pointer with caution
边栏推荐
猜你喜欢
Unity 射线与碰撞范围检测【踩坑记录】
List of top ten domestic industrial 3D visual guidance enterprises in 2022
A comprehensive and detailed explanation of static routing configuration, a quick start guide to static routing
JVM memory and garbage collection-3-object instantiation and memory layout
COMSOL --- construction of micro resistance beam model --- final temperature distribution and deformation --- addition of materials
Alo who likes TestMan
软件测试笔试题你会吗?
nmap工具介绍及常用命令
JVM memory and garbage collection-3-runtime data area / method area
leetcode 869. Reordered Power of 2 | 869. 重新排序得到 2 的幂(状态压缩)
随机推荐
Relationship between bizdevops and Devops
Where to think
Clickhouse principle analysis and application practice "reading notes (8)
Strive to ensure that domestic events should be held as much as possible, and the State General Administration of sports has made it clear that offline sports events should be resumed safely and order
微软 AD 超基础入门
XMeter Newsletter 2022-06|企业版 v3.2.3 发布,错误日志与测试报告图表优化
VIM use
[error] error loading H5 weight attributeerror: 'STR' object has no attribute 'decode‘
Talk about the cloud deployment of local projects created by SAP IRPA studio
魚和蝦走的路
I don't know. The real interest rate of Huabai installment is so high
Introduction à l'outil nmap et aux commandes communes
The generosity of a pot fish
leetcode 865. Smallest Subtree with all the Deepest Nodes | 865. The smallest subtree with all the deepest nodes (BFs of the tree, parent reverse index map)
MQTT X Newsletter 2022-06 | v1.8.0 发布,新增 MQTT CLI 和 MQTT WebSocket 工具
Leetcode question brushing record | 27_ Removing Elements
Analysis ideas after discovering that the on duty equipment is attacked
Direct addition is more appropriate
Wechat applet uniapp page cannot jump: "navigateto:fail can not navigateto a tabbar page“
Leetcode question brushing record | 283_ Move zero