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:
Code:
void MainWindow::ProcessingCallback(Channel &Ch, SignalInfo &Info)
{
try
{
// Update the eVision image with the acquired image data
UpdateImageConfig(*Info.Surf, EImgSrc);
// Convert EImage to Mat
Mat cvImg(EImgSrc.GetHeight(), EImgSrc.GetWidth(), CV_8UC3, EImgSrc.GetGenericImagePtr());
// Display the new image
imshow( "Display window", cvImg );
}
catch (Euresys::MultiCam::Exception &e)
{
// Display the exceptions...
}
}
So in the same way with Qt I done the next code:
Code:
void MainWindow::ProcessingCallback(Channel &Ch, SignalInfo &Info)
{
try
{
// Update the eVision image with the acquired image data
UpdateImageConfig(*Info.Surf, EImgSrc);
// Convert EImage to QImage
QImage imaq
((const uchar
*)EImgSrc.
GetGenericImagePtr(), EImgSrc.
GetWidth(), EImgSrc.
GetHeight(), EImgSrc.
GetBitsPerRow(),
QImage::Format_RGB888);
// Display the new image
painter.
drawImage(QPoint(0,
0), imaq
);
}
catch (Euresys::MultiCam::Exception &e)
{
// Display the exceptions...
}
}
But in this case, there are no display and output show this message :
Code:
QPainter::begin: Paint device returned engine
== 0, type
: 1
Could you advice me please?
:)
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,
_
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. :D
Quote:
store the image and call update() and draw in paintEvent
So this is my new code.
Code:
{
painter.
drawImage(QPoint(0,
0),currentImage
);
}
void MainWindow::ProcessingCallback(Channel &Ch, SignalInfo &Info)
{
try
{
// Update the eVision image with the acquired image data
UpdateImageConfig(*Info.Surf, EImgSrc);
// Inversion between the first and the third color component of each pixel component (EImage is BGR coded)
for(INT32 x=0; x<EImgSrc.GetWidth(); x++)
{
for(INT32 y=0; y<EImgSrc.GetHeight(); y++)
{
EC24 pixE = EImgSrc.GetPixel(x, y);
UINT8 temp = pixE.m_un8C2;
pixE.m_un8C2 = pixE.m_un8C0;
pixE.m_un8C0 = temp;
EImgSrc.SetPixel(pixE, x, y);
}
}
// Convert EImage to QImage
QImage newImage
((const uchar
*)EImgSrc.
GetGenericImagePtr(), EImgSrc.
GetWidth(), EImgSrc.
GetHeight(),
QImage::Format_RGB888);
// Display the new image
currentImage = newImage;
this->update();
}
catch (Euresys::MultiCam::Exception &e)
{
// Display the exceptions...
}
}
With
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "EasyMultiCam.h"
using namespace Euresys::MultiCam;
using namespace Euresys::eVision::EasyMultiCam;
{
Q_OBJECT
public:
MainWindow();
EImageC24 EImgSrc;
// ...
public slots:
void ProcessingCallback(Channel &Ch, SignalInfo &Info);
// ...
private slots:
// ...
};
#endif // MAINWINDOW_H
Thank you again for the efficiency of your advices.
Bye!
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