PDA

View Full Version : Streaming QImage (QByteArray, QDataStream, QBuffer)



knarz
15th January 2009, 17:26
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:

out.setVersion(QDataStream::Qt_4_4);
out << (quint16)0;
out << image;
out.device()->seek(0);
out << (quint16)(ba.size() - sizeof(quint16));

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

Most code i found was:


QImage* image = new QImage("mask.jpg");
QByteArray ba;
QBuffer buffer( &ba );
buffer.open(QIODevice::WriteOnly);

QDataStream out(&buffer);

out << image;


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 :D

thanks ;)

wysota
16th January 2009, 10:28
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.

knarz
17th January 2009, 12:16
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.

wysota
17th January 2009, 13:08
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.

knarz
17th January 2009, 22:57
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.

wysota
17th January 2009, 23:05
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.