Access IP camera from Qt



  • I need to access a IP camera from my Qt Application. I'm using the src of the camera image (http://192.168.0.110/image/jpeg.cgi) and updating this image with a Timer on QML.

    Timer {
            interval: 200
            running: true
            repeat: true
            onTriggered:  {
                image1.cache =false;
                image1.source = "http://192.168.0.110/image/jpeg.cgi";
            }
        }
    

    Executing only the code with the Camera, it works fine. The problem happen when I load all the application, the Camera is updated very slow. I'm using a embedded Linux and the resources are limited (512MB RAM, ARM Cortex-A5 500 MHz ). Besides, I need to use the QT4.8 to do this (necessarily).

    Any idea to improve the performance? Thanks


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What sizes are the images ? Can you configure your camera to send something more "friendly" e.g. RGB images ?



  • Thanks for your answer @SGaist . Well, By default my camera configurations is: Resolution: 320x240, FPS: 15, Jpeg Quality : Medium. With these configurations, is very slow the update of the image.

    I tryed to configure as: Resolution: 160x120, FPS: 15, Jpeg Quality: Very slow. Its works more fast, but the quality is very bad.

    I think that maybe there are another way to do camera streamming, without get of the image from link (http://192.168.0.110/image/jpeg.cgi) in a interval.. :(


  • Lifetime Qt Champion

    What type of camera is it ?



  • "Very slow" doesn't tell much. But apparently you are asking for a frame every 200 ms, giving 5 fps, which obviously is very slow if you expect normal video display quality...



  • @SGaist

    I'm using a camera D-LINK DCS-930L. Thanks



  • @mvuori Yes, I think strange too. But, I'm using the same program to do written on serial port. Each written on serial port is with interval around 300ms. The return of the serial port, is writing on QML too.


  • Lifetime Qt Champion

    Are you doing any blocking function call ? e.g. for your serial port ?



  • @SGaist No, I'm using a Qthread to execute the serial port


  • Lifetime Qt Champion

    Can you describe the various parts of your application so we can ensure that they are not influencing each other.

    By the way, there's no need to set cache each time. Just set the property where you declarer image1. That's one less thing consuming time uselessly.



  • @SGaist It's my main function:

    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QDeclarativeView *engine = new QmlApplicationViewer();
        
        Gps *gps = new Gps(); // Class to read Gps (serial port 0). Interval: 10000ms
        
        SerialPort *serial = new SerialPort(); // Read Serial Port (serial port 1). Interval: 300ms
        
       if(serial->getMonitor()) {
            qDebug() << "Starting Monitor";
            Monitor *monitor = new Monitor(engine, serial);
            serial->setMonitor(monitor);
        }
        return app.exec();
    }
    

    The class SerialPort start the write on serial port with a forever loop. Its working well, without delays.

    When the serial read the response, the response is sent to monitor Class and this class is responsable to format the digits and write on screen (QML file). Therefore, each 300 ms my QML file is updated too (with the response of serial port).


  • Lifetime Qt Champion

    Then where's the camera in that setup ?



  • @SGaist The camera is loaded in a different QML, look:

    import QtQuick 1.1
    
    Rectangle {
        width: 300
        height: 400
    
        Image {
            id: camera1
            objectName: "camera1"
            x: 39
            y: 0
            width: 160
            height: 120
            source: "http://192.168.0.110/image/jpeg.cgi"
            cache: false
    
            Timer {
                interval: 300
                running: true
                repeat: true
                onTriggered: {
                    camera1.source = "http://192.168.0.110/image/jpeg.cgi";
                }
            }
        }
    ...
    }
    
    

    The QML is loaded on Monitor class:

    Monitor::Monitor(QDeclarativeView *engine, Monitor *m)
    {
        engine->setSource(QUrl("qrc:/views/Monitor.qml"));
    
        window = qobject_cast< QObject * >( engine->rootObject() );
    
        engine->showFullScreen();
        monitor = m;
    
        engine->rootContext()->setContextProperty("mainmonitor",this);
    }
    


  • You can also try to load next image when previous one is loaded by checking the status.
    I use this in my application when loading jpeg from cameras.
    You just need to set 2 Image objects and show them when Image is ready



  • @kolegs how I can do to check the status? Could you show an exemple? Are you using the QML Time to update the frames? Thank you



  • You just need to create two Images with same position add property

    visible: status == Image.ready
    

    and on also add sth like this

    onStatusChanged:{
       if(status == Image.ready){
          //here reload the other image
          image2.source = "";
          image2.source = cameraSource;
       }
    }
    

    Add the same thing in image2 but this timer reload image1

    onStatusChanged:{
       if(status == Image.ready){
          //here reload the other image
          image1.source = "";
          image1.source = cameraSource;
       }
    }
    

    Also at creation just set source to cameraSource for one image and for the other leave it empty,.

    Hope it helps.



  • @kolegs Thank you so much. I created this code and the performance was very better. I'm reading two IP cameras now with it.

    Of course that the delay is existing (each 2 seconds the image is updated). I think that I need to improve my code. I'm using 98% of my CPU, but I need to do many routines :(

    Thank you so much again


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.