Results 1 to 4 of 4

Thread: How to convert EImage into QImage and show it in a QWidget?

  1. #1
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question How to convert EImage into QImage and show it in a QWidget?

    Hello everybody,

    I'm working on a video acquisition project with an EURESYS frame grabber (Picolo).
    I develop on Qt Creator EDI (Qt 4.8.3 based) with MS VC++ 10 compiler and I use eVision 6.7.1 library.

    There is no problems with board configuration and image acquisition.
    With OpenCV library, I can convert EImage to Mat and show it in a secondary window:

    Qt Code:
    1. void MainWindow::ProcessingCallback(Channel &Ch, SignalInfo &Info)
    2. {
    3. try
    4. {
    5. // Update the eVision image with the acquired image data
    6. UpdateImageConfig(*Info.Surf, EImgSrc);
    7.  
    8. // Convert EImage to Mat
    9. Mat cvImg(EImgSrc.GetHeight(), EImgSrc.GetWidth(), CV_8UC3, EImgSrc.GetGenericImagePtr());
    10.  
    11. // Display the new image
    12. imshow( "Display window", cvImg );
    13. }
    14. catch (Euresys::MultiCam::Exception &e)
    15. {
    16. // Display the exceptions...
    17. }
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    So in the same way with Qt I done the next code:
    Qt Code:
    1. void MainWindow::ProcessingCallback(Channel &Ch, SignalInfo &Info)
    2. {
    3. try
    4. {
    5. // Update the eVision image with the acquired image data
    6. UpdateImageConfig(*Info.Surf, EImgSrc);
    7.  
    8. // Convert EImage to QImage
    9. QImage imaq((const uchar*)EImgSrc.GetGenericImagePtr(), EImgSrc.GetWidth(), EImgSrc.GetHeight(), EImgSrc.GetBitsPerRow(), QImage::Format_RGB888);
    10.  
    11. // Display the new image
    12. QPainter painter(this);
    13. painter.drawImage(QPoint(0, 0), imaq);
    14. }
    15. catch (Euresys::MultiCam::Exception &e)
    16. {
    17. // Display the exceptions...
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    But in this case, there are no display and output show this message :
    Qt Code:
    1. QPainter::begin: Paint device returned engine == 0, type: 1
    To copy to clipboard, switch view to plain text mode 

    Could you advice me please?
    Last edited by FloFox; 14th February 2013 at 14:52.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to convert EImage into QImage and show it in a QWidget?

    You cannot paint onto a widget outside of its paintEvent() method.

    Some options:
    - store the image and call update() and draw in paintEvent
    - use a child widget that can display images and set the image there

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    FloFox (15th February 2013)

  4. #3
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: How to convert EImage into QImage and show it in a QWidget?

    Thank you anda_skoa,

    I used your first advice and it's working.

    store the image and call update() and draw in paintEvent
    So this is my new code.
    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.drawImage(QPoint(0,0),currentImage);
    5. }
    6.  
    7. void MainWindow::ProcessingCallback(Channel &Ch, SignalInfo &Info)
    8. {
    9. try
    10. {
    11. // Update the eVision image with the acquired image data
    12. UpdateImageConfig(*Info.Surf, EImgSrc);
    13.  
    14. // Inversion between the first and the third color component of each pixel component (EImage is BGR coded)
    15. for(INT32 x=0; x<EImgSrc.GetWidth(); x++)
    16. {
    17. for(INT32 y=0; y<EImgSrc.GetHeight(); y++)
    18. {
    19. EC24 pixE = EImgSrc.GetPixel(x, y);
    20. UINT8 temp = pixE.m_un8C2;
    21. pixE.m_un8C2 = pixE.m_un8C0;
    22. pixE.m_un8C0 = temp;
    23. EImgSrc.SetPixel(pixE, x, y);
    24. }
    25. }
    26.  
    27. // Convert EImage to QImage
    28. QImage newImage((const uchar*)EImgSrc.GetGenericImagePtr(), EImgSrc.GetWidth(), EImgSrc.GetHeight(), QImage::Format_RGB888);
    29.  
    30. // Display the new image
    31. currentImage = newImage;
    32. this->update();
    33.  
    34. }
    35. catch (Euresys::MultiCam::Exception &e)
    36. {
    37. // Display the exceptions...
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 
    With
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. #include "EasyMultiCam.h"
    7.  
    8. using namespace Euresys::MultiCam;
    9. using namespace Euresys::eVision::EasyMultiCam;
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. MainWindow();
    17. EImageC24 EImgSrc;
    18. QImage currentImage;
    19. // ...
    20.  
    21. public slots:
    22. void ProcessingCallback(Channel &Ch, SignalInfo &Info);
    23. // ...
    24.  
    25. private slots:
    26. void paintEvent(QPaintEvent *);
    27. // ...
    28.  
    29. };
    30.  
    31. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Thank you again for the efficiency of your advices.

    Bye!
    Last edited by FloFox; 15th February 2013 at 14:30.

  5. #4
    Join Date
    Jun 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to convert EImage into QImage and show it in a QWidget?

    Hi, I have setup a euresys multicam and connected it to a windows computer. But I am having trouble writing a program in Qt that will allow me to simply capture a pciture/frame from a video. I have been searching online for how to program this thing and I cant seem to find anything.

    I found this website that kind of explains how, but I end up getting a lot of errors.

    http://mariotapilouw.blogspot.ca/201...m-library.html

    Can you please direct me to some website that might explain how to program the euresys multicam with Qt. Or since you've done it already, maybe you can help me out a bit. I'm just not sure how to program in qt with the MultiCam library and these euresys cameras. I can program no problem with usb cameras, but these ones are different.

    Thanks, I appreciate your help.

    th
    Last edited by th; 20th June 2013 at 15:57.

Similar Threads

  1. IPC- char * to WCHAR* convertion?
    By Ricardo_arg in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2010, 18:55
  2. Text file to PDF convertion using C++ code
    By joseph in forum General Discussion
    Replies: 2
    Last Post: 21st August 2008, 01:28
  3. Convertion between QLineEdit formated to Double
    By vcp in forum Qt Programming
    Replies: 4
    Last Post: 13th June 2008, 17:15
  4. Time convertion
    By rajeshs in forum Qt Programming
    Replies: 3
    Last Post: 5th June 2008, 11:22

Tags for this Thread

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.