Results 1 to 11 of 11

Thread: Drawing over an image displayed on a QLabel

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Drawing over an image displayed on a QLabel

    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
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Drawing over an image displayed on a QLabel

    Quote Originally Posted by franco.amato View Post
    Good morning to all
    Wow, 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 )

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing over an image displayed on a QLabel

    Quote Originally Posted by Lykurg View Post
    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
    Franco Amato

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Drawing over an image displayed on a QLabel

    A QImage is also fine:
    Qt Code:
    1. QImage img;
    2. QPainter p(&img);
    3. // do your painting using the painter
    4. p.end();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2007
    Posts
    27
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing over an image displayed on a QLabel

    or take a view at the QGraphicsView framework...

    Greetz Yakin

  6. #6
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing over an image displayed on a QLabel

    Quote Originally Posted by Lykurg View Post
    A QImage is also fine:
    Qt Code:
    1. QImage img;
    2. QPainter p(&img);
    3. // do your painting using the painter
    4. p.end();
    To copy to clipboard, switch view to plain text mode 
    I tried this code as suggested by you:

    Qt Code:
    1. QImage image = IplImageToQImage( m_resizedImage );
    2.  
    3. QPainter p(&image);
    4. int rx, ry;
    5. //// processing
    6. p.end();
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by franco.amato; 23rd August 2010 at 17:36.
    Franco Amato

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Drawing over an image displayed on a QLabel

    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.

  8. #8
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing over an image displayed on a QLabel

    Quote Originally Posted by Lykurg View Post
    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
    Franco Amato

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Drawing over an image displayed on a QLabel

    Yes, because a QWidget is lighter then a QLabel. What's about making a complete custom viewer widget?
    Qt Code:
    1. void Viewer::update(QImage newImage, Foo CircleInformations)
    2. {
    3. m_image = newImage;
    4. m_circles = CircleInformations;
    5. // set size policies of your window according to the image size, of if you sure it will not change then leave it.
    6. update();
    7. }
    8.  
    9. void Viewer::paintEvent(QPaintEvent *e)
    10. {
    11. QPainter p(this);
    12. p.drawImage(m_image);
    13. // here do your circle painting according to m_circles.
    14. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing over an image displayed on a QLabel

    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
    Franco Amato

  11. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing over an image displayed on a QLabel

    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

Similar Threads

  1. problem in drawing image in QLabel!
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2010, 15:16
  2. can the image be displayed as it is in chips prog..
    By sh123 in forum Qt Programming
    Replies: 11
    Last Post: 7th February 2009, 08:15
  3. image not displayed ...
    By sh123 in forum Qt Tools
    Replies: 4
    Last Post: 15th December 2008, 13:07
  4. no image displayed on QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2007, 12:33
  5. JPEG Image isn't displayed!?
    By GodOfWar in forum Qt Programming
    Replies: 9
    Last Post: 16th April 2007, 15:01

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.