【飛凌嵌入式 OK3399-C+開(kāi)發(fā)板試用體驗(yàn)】使用多媒體QCamera和QPointer相關(guān)類(lèi)
作者:donatello1996
參考了GitHub上某位大佬的代碼,使用QCamera QCameraInfo QCameraImageCapture QPointer QActionGroup這些類(lèi)來(lái)實(shí)現(xiàn)USB攝像頭圖像讀取,其中三個(gè)QCamera的相關(guān)類(lèi)需要在pro文件中加入** **widgets即多媒體類(lèi)庫(kù)支持:
QT += core gui ** **widgets
然后是定義相關(guān)指針,我試過(guò)直接用*指針來(lái)定義不行,必須要用模板類(lèi)指針:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void refreshCameras();
void refreshFormats();
void refreshResolutions();
void setCamera(QCameraInfo info);
void setFormat(QString format);
void setResolution(QSize resolution);
void disconnectCamera();
void updateImage();
private:
Ui::MainWindow *ui;
QList<QCameraInfo> cameras;
QStringList formats;
QList<QSize> resolutions;
<font color="Blue">QCamera *camera;
QPointer<QCameraImageCapture> capture;</font>
VideoSu**ce su**ce;
QPointer<QActionGroup> ActionGroupCameras;
QPointer<QActionGroup> ActionGroupFormats;
QPointer<QActionGroup> ActionGroupResolutions;
};
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
thread1 = new mythread(this);
refreshCameras();
connect(&su**ce, &VideoSu**ce::newImageReady, this, &MainWindow::updateImage);
}
QCamera類(lèi)對(duì)象camera需要跟QCameraInfo類(lèi)的對(duì)象info綁定相關(guān)信息,查看QT庫(kù)定義,只在構(gòu)造函數(shù)中綁定QCameraInfo類(lèi),因此每次切換信息都需要使用new的方式綁定,QCameraImageCapture類(lèi)同理:
void MainWindow::setCamera(QCameraInfo info)
{
delete camera;
delete capture;
camera = new QCamera(info, this);
capture = new QCameraImageCapture(camera, this);
camera->setViewfinder(&su**ce);
camera->load();
camera->start();
//refreshFormats();
refreshResolutions();
ui->actionDisconnect->setEnabled(true);
}
void MainWindow::disconnectCamera()
{
delete camera;
delete capture;
for (QAction *action : ui->menuCameras->actions()) {
action->setChecked(false);
}
ui->actionDisconnect->setEnabled(false);
}
void MainWindow::refreshCameras()
{
disconnectCamera();
cameras = QCameraInfo::availableCameras();
delete ActionGroupCameras;
ActionGroupCameras = new QActionGroup(this);
ui->menuCameras->clear();
if (cameras.size())
{
ui->menuCameras->setEnabled(true);
for (const QCameraInfo &info: cameras)
{
QAction *action = new QAction(info.description(), ActionGroupCameras); // capture->imageCodecDescription(codec)
action->setCheckable(true);
ui->menuCameras->addAction(action);
connect(action, &QAction::triggered, [=]()
{
setCamera(info);
});
}
for (const QCameraInfo &info: cameras)
{
qDebug() << "Opening camera:" << info.deviceName();
qDebug() << "\t- Description:" << info.description();
qDebug() << "\t- Position:" << info.position();
}
} else
{
ui->menuCameras->setDisabled(true);
}
}
void MainWindow::updateImage()
{
ui->imageLabel->setPixmap(su**ce.getPixmap().scaledToWidth(ui->imageLabel->width(), Qt::SmoothTransformation));
}
這些都做好之后就在ui文件中添加下拉菜單即可,有刷新攝像頭列表信息,斷開(kāi)連接,讀取攝像頭信息到列表等功能:
相關(guān)產(chǎn)品 >
-
FET3399-C核心板
飛凌RK3399安卓高性能核心板采用 采用六核Rockchip RK3399芯片,雙Cortex-A72大核+四Cortex-A53小核結(jié)構(gòu),對(duì)整數(shù)、浮點(diǎn)、內(nèi)存等作了大幅優(yōu)化,在整體性能、功耗及核心面積三個(gè)方面提升。以下將對(duì)瑞芯微芯片RK3399參數(shù),RK3399核心板方案及其性能做具體介紹。如您對(duì)飛凌RK3399系列核心板有興趣,歡迎咨詢(xún)了解。
了解詳情
-
OK3399-C開(kāi)發(fā)板
飛凌嵌入式RK3399安卓開(kāi)發(fā)板主芯片采用高性能六核CPU Rockchip RK3399,GPU采用Mail-T860四核 GPU,RK3399作為目RK產(chǎn)品線中低功耗、高性能的代表,可滿足人臉識(shí)別設(shè)備、機(jī)器人、無(wú)人機(jī)、IoT物聯(lián)網(wǎng)領(lǐng)域應(yīng)用。飛凌RK3399開(kāi)發(fā)板在整體性能、功耗及核心面積做了大幅度優(yōu)化,更加滿足工業(yè)設(shè)計(jì)需求。飛凌RK3399開(kāi)發(fā)板為進(jìn)一步減少用戶(hù)二次開(kāi)發(fā)難度,開(kāi)放了底板原理圖,并提供了RK3399用戶(hù)手冊(cè)、芯片手冊(cè),加上優(yōu)質(zhì)的技術(shù)服務(wù),讓您的方案從構(gòu)思到上市時(shí)間縮短。
了解詳情


