PDA

View Full Version : Drawing over an image displayed on a QLabel



franco.amato
20th August 2010, 18:56
Good morning to all,
I'm developing a camera viewer displaying the camera frames on a QLabel.
I need to draw some circle over the camera frames before display them how can I do?
Best Regards,
Franco

Lykurg
20th August 2010, 19:17
Good morning to allWow, there must be a time gap between Italy and Germany...

I guess you get your images from your camera as QPixmap. Then simple create a QPainter and set it to the pixmap and paint on it.
QPainter::QPainter ( QPaintDevice * device )

franco.amato
21st August 2010, 00:13
Wow, there must be a time gap between Italy and Germany...
I'm in sud America ;-)


I guess you get your images from your camera as QPixmap. Then simple create a QPainter and set it to the pixmap and paint on it.
I get images from the camera as char aray, then I pack the array into an IplImage (OPenCV) for further processing and then I convert to a QImage to display it.
What I would do is this:
after the processing I convert to a QImage -> at this point I would draw the result of the processing ( some circles ) over the QImage so the user can see it.

Regards,
Franco

Lykurg
21st August 2010, 23:31
A QImage is also fine:
QImage img;
QPainter p(&img);
// do your painting using the painter
p.end();

yakin
22nd August 2010, 12:43
or take a view at the QGraphicsView framework...

Greetz Yakin

franco.amato
23rd August 2010, 17:30
A QImage is also fine:
QImage img;
QPainter p(&img);
// do your painting using the painter
p.end();


I tried this code as suggested by you:


QImage image = IplImageToQImage( m_resizedImage );

QPainter p(&image);
int rx, ry;
//// processing
p.end();

and I got the following error:
I can not draw on a image with the QImage::Format_Indexed8 format.
How can I do?

Best Regards,
Franco

Lykurg
23rd August 2010, 19:56
Transform it to a pixmap or to a different format on which you can paint. Sorry but I don't have the time right now to determinate on wich format one can paint. But if you transform better check if a overlay widget is not faster. I assume your images have always the same size, then you should probably better overlay your label with a normal transparent widget and do the painting there.

But do both variant and benchmark them.

franco.amato
23rd August 2010, 23:10
Transform it to a pixmap or to a different format on which you can paint. Sorry but I don't have the time right now to determinate on wich format one can paint. But if you transform better check if a overlay widget is not faster. I assume your images have always the same size, then you should probably better overlay your label with a normal transparent widget and do the painting there.

But do both variant and benchmark them.

Yes my images have always the same size ( are frames from a video camera ).
So you suggest to me to paint over a widget instead of a QLabel?

regards,
Franco

Lykurg
24th August 2010, 07:11
Yes, because a QWidget is lighter then a QLabel. What's about making a complete custom viewer widget?
void Viewer::update(QImage newImage, Foo CircleInformations)
{
m_image = newImage;
m_circles = CircleInformations;
// set size policies of your window according to the image size, of if you sure it will not change then leave it.
update();
}

void Viewer::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.drawImage(m_image);
// here do your circle painting according to m_circles.
}

franco.amato
25th August 2010, 00:27
Hi,
thank you.
Is possible in a QWidget ( or another widget ) to display more than 1 image orizontally?
For example at position 0 I display image_1,
at position ( 0 + width_of_image_1 + 20px ) I display image_2,
at position ( 0 + width_of_image_1 + 20 px + width_of_image_2 + 20 px ) I display image_3?
Best Regards,
Franco

aamer4yu
25th August 2010, 05:40
Is possible in a QWidget ( or another widget ) to display more than 1 image orizontally?
Yes,, why not.. its same as fitting three rectangles inside one big rectangle... isnt it :rolleyes: