Good morning.
I'm writing a camera viewer and I have problem displaying the frames.
To display them I wrote a very little CameraRenderer ( inherited from QWidget ) widget.
Here the code.
.h
#ifndef _CAMERARENDERER_H_
#define _CAMERARENDERER_H_
#include <QWidget>
class CCameraRenderer
: public QWidget{
Q_OBJECT
public:
CCameraRenderer
(QWidget* parent
=0);
~CCameraRenderer();
protected:
/* paint event */
private:
};
#endif //#ifndef _CAMERARENDERER_H_
#ifndef _CAMERARENDERER_H_
#define _CAMERARENDERER_H_
#include <QWidget>
class CCameraRenderer : public QWidget
{
Q_OBJECT
public:
CCameraRenderer(QWidget* parent=0);
~CCameraRenderer();
void setImage(QPixmap*);
protected:
/* paint event */
virtual void paintEvent( QPaintEvent* event );
private:
QPixmap* m_image;
};
#endif //#ifndef _CAMERARENDERER_H_
To copy to clipboard, switch view to plain text mode
.cpp
#include "CameraRenderer.h"
/*Qt*/
#include <QPainter>
CCameraRenderer
::CCameraRenderer(QWidget* parent
) {
setFixedSize
( QSize(640,
480) );
}
CCameraRenderer::~CCameraRenderer()
{
}
void CCameraRenderer
::setImage(QPixmap* image
) {
//m_image = QPixmap();
m_image = image;
}
{
p.
setRenderHint( QPainter::Antialiasing,
true );
// image
p.drawPixmap( 0, 0, *m_image );
}
#include "CameraRenderer.h"
/*Qt*/
#include <QPainter>
CCameraRenderer::CCameraRenderer(QWidget* parent)
: QWidget(parent)
{
setFixedSize( QSize(640, 480) );
m_image = new QPixmap();
}
CCameraRenderer::~CCameraRenderer()
{
}
void CCameraRenderer::setImage(QPixmap* image)
{
//m_image = QPixmap();
m_image = image;
}
void CCameraRenderer::paintEvent( QPaintEvent* pe )
{
QPainter p(this);
p.setRenderHint( QPainter::Antialiasing, true );
// image
p.drawPixmap( 0, 0, *m_image );
}
To copy to clipboard, switch view to plain text mode
then I have the application where I have a QTimer and periodically I get a frame from the camera that I would display. The class that manage the camera is CVistaCamera.
Here the main code:
.h
class CVistaCamera
: public QObject{
Q_OBJECT
public:
~CVistaCamera();
int InitCamera();
void CloseCamera();
VC_VARS* getStructPtr();
public slots:
void onUpdate(); //<-- called in a timer event where I get a camera frame
signals:
void sig_stopTimer();
void sig_startTimer( int );
void sig_updateDisplay
( QPixmap* );
//<---should display the frame content
private:
int m_fVcOpen;
VC_VARS* pVar;
unsigned char* pImageData;
DWORD ImageSize;
DWORD vcVideoSource;
};
#endif //_VISTACAMERA_H_
class CVistaCamera : public QObject
{
Q_OBJECT
public:
CVistaCamera(QObject *parent = 0);
~CVistaCamera();
int InitCamera();
void CloseCamera();
VC_VARS* getStructPtr();
public slots:
void onUpdate(); //<-- called in a timer event where I get a camera frame
signals:
void sig_stopTimer();
void sig_startTimer( int );
void sig_updateDisplay( QPixmap* ); //<---should display the frame content
private:
int m_fVcOpen;
VC_VARS* pVar;
unsigned char* pImageData;
DWORD ImageSize;
DWORD vcVideoSource;
QPixmap* pixmap;
};
#endif //_VISTACAMERA_H_
To copy to clipboard, switch view to plain text mode
and the main methods:
void CVistaCamera::onUpdate() //called periodically with a QTimer
{
VC_VARS* pVc = getStructPtr();
// get a frame
rc = VcGetImage( pImageData, ImageSize, &retLen );
if ( rc == VC_SUCCESS )
{
pixmap->loadFromData( pImageData, ImageSize );
emit sig_updateDisplay( pixmap );
}
else
{
// error - camera disconnected?
VcClose();
m_fVcOpen = 0;
}
}
void CVistaCamera::onUpdate() //called periodically with a QTimer
{
VC_VARS* pVc = getStructPtr();
// get a frame
rc = VcGetImage( pImageData, ImageSize, &retLen );
if ( rc == VC_SUCCESS )
{
pixmap->loadFromData( pImageData, ImageSize );
emit sig_updateDisplay( pixmap );
}
else
{
// error - camera disconnected?
VcClose();
m_fVcOpen = 0;
}
}
To copy to clipboard, switch view to plain text mode
the signal sig_updateDisplay is connected with a the slot onUpdateDisplay so:
connect( m_vistaCamera,
SIGNAL( sig_updateDisplay
(QPixmap*) ),
this,
SLOT( onUpdateDisplay
(QPixmap*) ) );
connect( m_vistaCamera, SIGNAL( sig_updateDisplay(QPixmap*) ), this, SLOT( onUpdateDisplay(QPixmap*) ) );
To copy to clipboard, switch view to plain text mode
and here the slot:
void VistaIrisCollector
::onUpdateDisplay(QPixmap* pixmap
) {
ui.display->setImage( pixmap );
ui.display->repaint();
}
void VistaIrisCollector::onUpdateDisplay(QPixmap* pixmap )
{
ui.display->setImage( pixmap );
ui.display->repaint();
}
To copy to clipboard, switch view to plain text mode
In the window I don't see nothing, I don't know why.
I would have a help.
Best Regards,
Franco
Bookmarks