0

I need to send IplImages fetched from camera with UDP socket. I'm using Qt. The application has two parts. The server should fetch images from digital camera and send them to a specific port via upd (broadcasting). Clients are GUI applications. They will receive images and display them on a QLabel.

I'm using OpenCV for images, so my input of camera is IplImage. I know how to convert it to QImage/QPixmap and display it on a label. But can't find a way to send IplImage through a udp socket... QUdpSocet::writeDatagram only accepts QByteArray so I neet to convert IplImage to QByteArray and this should be very fast (It's not appropriate to convert images on server).

Michal Kottman
  • 16,375
  • 3
  • 47
  • 62
sorush-r
  • 10,490
  • 17
  • 89
  • 173
  • In Java, there is an IplImage.getByteBuffer() function. I can't tell if it exists for Qt. If so it will be the thing you are looking for, if not, you can always write your own serialization function for IplImage – Tim Meyer Dec 01 '11 at 08:02
  • Related: http://stackoverflow.com/questions/5126923/boost-asio-send-opencv-iplimage-from-ubuntu-server-to-win7-client – HostileFork says dont trust SE Dec 01 '11 at 08:04
  • There is `IplImage::imageData` field in the `IplImage` class. I'm not sure if that's the actual data or not... I'll try. – sorush-r Dec 01 '11 at 08:05

1 Answers1

1

I see you can create a QByteArray with :

QByteArray ( const char * data, int size )

And on the IplImage part you have:

 int imageSize

    Image data size in bytes. For interleaved data, this equals image->height * image->widthStep

char* imageData

    A pointer to the aligned image data. Do not assign imageData directly. Use SetData().

So it should be easy as QByteArray(image->imageData, image->imageSize);

Adrian
  • 2,028
  • 2
  • 17
  • 28
  • Image size is larger than could be sent via udp.... can't see result but seems to work properly... – sorush-r Dec 01 '11 at 10:28
  • 2
    @SorushRabiee The documentation for QUdpSocket::writeDatagrams clearly states: "Sending datagrams larger than 512 bytes is in general disadvised, as even if they are sent successfully, they are likely to be fragmented by the IP layer before arriving at their final destination." From expirience, it varies from OS to OS. So better chop up your data or use QTcpSocket (which is clearly the better advise, given that UDP packets could be lost and you probably do not want your pictures to lose arbitrary pices of data. – danimo Dec 01 '11 at 16:01
  • and of course chopping up packages means adding a protocol to put images in the right order, rerequest missing packets, etc. So really, use QTcpSocket unless you have a very, very, very good reason. – danimo Dec 01 '11 at 17:26