Results 1 to 6 of 6

Thread: Streaming QImage (QByteArray, QDataStream, QBuffer)

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Streaming QImage (QByteArray, QDataStream, QBuffer)

    Hi,
    first of all, great board.
    But i have a problem with understanding the flow of sending/streaming and packing of QImage format.
    - We (3 dudes) do a Project: Webcam-Chat
    Now we have the captureing (OpenCV), UI and Basic network support.
    - Now we stuck in sending and receiving QImage - i found some code here, but all have there differences and we don't know what would be the right and maybe the best way.

    First Idea was to send QImage in QDataStream, next was QImage -> QByteArray -> QDataStream, next one QImage -> QBuffer -> QByteArray -> QDataStream

    so now we're confused and overcharged.

    - So, first Question, what would be the best Way t?!
    - What's with the initialization of the Steam, in some code snippets there's:

    Example:
    Qt Code:
    1. out.setVersion(QDataStream::Qt_4_4);
    2. out << (quint16)0;
    3. out << image;
    4. out.device()->seek(0);
    5. out << (quint16)(ba.size() - sizeof(quint16));
    To copy to clipboard, switch view to plain text mode 

    in some code there's nothing of this mentioned. Is it, or is it not required for sending QImage?

    Most code i found was:

    Qt Code:
    1. QImage* image = new QImage("mask.jpg");
    2. QBuffer buffer( &ba );
    3. buffer.open(QIODevice::WriteOnly);
    4.  
    5. QDataStream out(&buffer);
    6.  
    7. out << image;
    To copy to clipboard, switch view to plain text mode 

    One of my dude's says that this won't work, at least witout the "initialization" (quint16) and so on...


    So question is now what procedure would be the best - and how to programm? - example or real code, would be the best

    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Streaming QImage (QByteArray, QDataStream, QBuffer)

    To me the best solution would be not to transfer the move image by image as changes between subsequent images are small, so it's faster to transfer only them. That's what most movie formats do and I suggest you use one. FFMpeg libs might come in handy but in general you can use any stream codec.

  3. #3
    Join Date
    Jan 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Streaming QImage (QByteArray, QDataStream, QBuffer)

    Quote Originally Posted by wysota View Post
    To me the best solution would be not to transfer the move image by image as changes between subsequent images are small, so it's faster to transfer only them. That's what most movie formats do and I suggest you use one. FFMpeg libs might come in handy but in general you can use any stream codec.

    Of course, you're absolutly right, but the major problem is transfering of QImage (or better IplImage (will save one step of converting)) we don't understand the handling of the network stuff. - At this moment we don't care about bandwidth.

    If someone could help us with some 'complete' code snipplets for sending and receiving - we would be soooo thankfull.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Streaming QImage (QByteArray, QDataStream, QBuffer)

    It's best to have a look at networking examples provided with Qt. Especially those based on UDP as you will probably want to start with UDP when transfering live videos.

    Oh, and try to give more adequate titles to the threads you start - "Streaming QImage" doesn't say anywhere your question actually concerns networking. Neither does the content of the thread, by the way.
    Last edited by wysota; 17th January 2009 at 12:13.

  5. #5
    Join Date
    Jan 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Streaming QImage (QByteArray, QDataStream, QBuffer)

    Hm, i thougt with streaming and/or QDataStream everbody would know it's all about networking?! - so, thats how i choose this titel.

    The problem we have is transfering of IplImage or QImage through the Internet/Network - the most solutions we found in this board weren't complett - and all solutions a different. The top question could also be, how to send and receive any typ of information/content through network - the size of data is variable. We want to avoid to destucture any typ of data (for the memory - IplImage / QImage)

    Sorry, we're all noobs, and it's our exam for a university project.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Streaming QImage (QByteArray, QDataStream, QBuffer)

    Quote Originally Posted by knarz View Post
    Hm, i thougt with streaming and/or QDataStream everbody would know it's all about networking?! - so, thats how i choose this titel.
    Not really. QDataStream has nothing to do with networking.

    The top question could also be, how to send and receive any typ of information/content through network - the size of data is variable. We want to avoid to destucture any typ of data (for the memory - IplImage / QImage)
    First place to look would be QTcpSocket and QUdpSocket. If you have specific questions after reading their docs, feel free to ask them.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.