Remco
25th August 2010, 16:42
Hello,
I'm trying to create a QT program to display the mjpg frames of my ip camera. For this i used QHttp without succes. On the internet i found out that it was also possible with QNetworkAccessManager. Now i've managed to show single images by using QNetworkReply and put it in a QPixmap. I'm sure it als must be possible for mjpg images but i can't figure out how.
Can anyone give me some advise. I can't use Opencv because finaly the application has to be written in QT embedded. If i'm right, i have to use the virtual framebuffer to show the mjpg images of the camera.
Below you can see my code.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_netwManager = new QNetworkAccessManager(this);
connect(m_netwManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
connect(m_netwManager,SIGNAL(authenticationRequire d(QNetworkReply*,QAuthenticator*)),this,SLOT(slot_ netwManagerFinished(QNetworkReply*,QAuthenticator* )));
}
void MainWindow::on_action_Download_triggered()
{
QUrl url(ui->txtImageAddress->text());
QNetworkRequest request(url);
m_netwManager->get(request);
}
void MainWindow::slot_netwManagerFinished(QNetworkReply *,QAuthenticator* auth)
{
auth->setUser("admin");
auth->setPassword("admin");
}
void MainWindow::slot_netwManagerFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError) {
reply->deleteLater();
return;
}
QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
if (contentType == "image/jpeg")
{
QVariant redir = reply->attribute(QNetworkRequest::RedirectionTargetAttrib ute);
if (redir.isValid()) {
QUrl url = redir.toUrl();
if (url.isRelative()) {
url.setScheme(reply->url().scheme());
url.setEncodedHost(reply->url().encodedHost());
}
QNetworkRequest req(url);
m_netwManager->get(req);
reply->deleteLater();
return;
}
QByteArray jpegData = reply->readAll();
QPixmap pixmap;
pixmap.loadFromData(jpegData);
ui->lblImage->setPixmap(pixmap);
reply->deleteLater();
}
else
{
//VIDEO MJPG DATA
}
}
I'm trying to create a QT program to display the mjpg frames of my ip camera. For this i used QHttp without succes. On the internet i found out that it was also possible with QNetworkAccessManager. Now i've managed to show single images by using QNetworkReply and put it in a QPixmap. I'm sure it als must be possible for mjpg images but i can't figure out how.
Can anyone give me some advise. I can't use Opencv because finaly the application has to be written in QT embedded. If i'm right, i have to use the virtual framebuffer to show the mjpg images of the camera.
Below you can see my code.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_netwManager = new QNetworkAccessManager(this);
connect(m_netwManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
connect(m_netwManager,SIGNAL(authenticationRequire d(QNetworkReply*,QAuthenticator*)),this,SLOT(slot_ netwManagerFinished(QNetworkReply*,QAuthenticator* )));
}
void MainWindow::on_action_Download_triggered()
{
QUrl url(ui->txtImageAddress->text());
QNetworkRequest request(url);
m_netwManager->get(request);
}
void MainWindow::slot_netwManagerFinished(QNetworkReply *,QAuthenticator* auth)
{
auth->setUser("admin");
auth->setPassword("admin");
}
void MainWindow::slot_netwManagerFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError) {
reply->deleteLater();
return;
}
QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
if (contentType == "image/jpeg")
{
QVariant redir = reply->attribute(QNetworkRequest::RedirectionTargetAttrib ute);
if (redir.isValid()) {
QUrl url = redir.toUrl();
if (url.isRelative()) {
url.setScheme(reply->url().scheme());
url.setEncodedHost(reply->url().encodedHost());
}
QNetworkRequest req(url);
m_netwManager->get(req);
reply->deleteLater();
return;
}
QByteArray jpegData = reply->readAll();
QPixmap pixmap;
pixmap.loadFromData(jpegData);
ui->lblImage->setPixmap(pixmap);
reply->deleteLater();
}
else
{
//VIDEO MJPG DATA
}
}