开发者

Compressing Iplimage to jpeg on memory

I am working on a project that I will transfer webcam images on the network , real time. But Iplimage has a big size so it do开发者_开发知识库es not fit in a udp packet. I have to compress it to jpeg format. I made some research many examples do save the picture on disk then read to the memory. But I want do it on memory. I am using Qt on my project.

Is there any solution for compressing Iplimage on memory ? May be Qt has a solution for that ?


Qt has QImageWriter class which supports JPEG format and allows specifying compression level. You can use it to save QImage data to QByteArray. Below is an example:

QImage image("/home/image_from.png");

QByteArray array;
QBuffer buffer(&array);

// write image to memory buffer
QImageWriter writer;
writer.setDevice(&buffer);
writer.setFormat("JPEG");
writer.setCompression(9);
writer.write(image);

or you can use QPixmap save method; it also allows specifying memory buffer as output device:

QImage image("/home/image_from.png");
QPixmap pixmap = QPixmap::fromImage(image);

QByteArray array;
QBuffer buffer(&array);
pixmap.save(&buffer, "JPEG", 9);

hope this helps, regards


Or since you are using openCV iplimage) you can just use imencode to convert to jpeg in a buffer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜