第一代码 在这段代码中,VideoCapture cap没有采用执行QFileDialog后获得的文件名(包含视频路径),即cap.open("fileName"),代码没有执行,而cap.open("G:mixer.avi"),代码正在执行。 这意味着如果视频路径直接在cap.open()中给出,那么代码正在执行,但它没有采用QFileDialog输出,即文件名作为输入。
void MainWindow::on_pushButton_clicked()
{
if(ui->radioButton->isChecked()) {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Video"), "G://", "All files (*.*);Video files(*.*)");
ui->lineEdit->setText(fileName);
VideoCapture cap
// cap.open("G:/mixer.avi");
cap.open("fileName");
connect(timer, SIGNAL(timeout()), this, SLOT(update_window()));
timer->start(20);}}
void MainWindow::update_window()
{
cap >> frame;
cvtColor(frame, frame, cv::COLOR_BGR2RGB);
qt_image = QImage((const unsigned char*) (frame.data), frame.cols, frame.rows,
QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(qt_image));
ui->label->resize(ui->label->pixmap()->size());
}
第二密码 :
在这段带有QFileDialogbox的代码中,视频正在显示,但它没有显示在QLabel中。
void MainWindow::on_pushButton_2_clicked()
{
if(ui->radioButton_2->isChecked()) {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Video"), "G://", "All files (*.*);Video files(*.*)");
ui->lineEdit->setText(fileName);
player = new QMediaPlayer;
vw=new QVideoWidget;
player->setVideoOutput(vw) ;
this->setCentralWidget(vw);
player->setMedia(QUrl::fromLocalFile(fileName));
vw->show();
player->play();
}
}
视频捕捉(const String & filename) 可以接受字符串作为输入,而不是QString。需要做2件事情。
VideoCapture
需要。