AVT相机arm版本SDK
This commit is contained in:
@@ -0,0 +1,305 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: Histogram.cpp
|
||||
|
||||
Description: populate histogram
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
[program/widget] is based in part on the work of
|
||||
the Qwt project (http://qwt.sf.net).
|
||||
=============================================================================*/
|
||||
|
||||
|
||||
#include <QLayout>
|
||||
#include "Histogram.h"
|
||||
|
||||
#include "../ExternLib/qwt/qwt_scale_engine.h"
|
||||
#include "../ExternLib/qwt/qwt_point_data.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_canvas.h"
|
||||
|
||||
|
||||
|
||||
class HistogramSource : public QwtSyntheticPointData
|
||||
{
|
||||
public:
|
||||
HistogramSource(const QVector<quint32>& h, int maxValue = 0, int offset = 0)
|
||||
: QwtSyntheticPointData(h.size(), QwtInterval(0, h.size()-1)),
|
||||
mMaxValue(maxValue), mOffset(offset)
|
||||
{
|
||||
mData = h;
|
||||
}
|
||||
|
||||
virtual QPointF sample( size_t index ) const
|
||||
{
|
||||
return QPointF((qreal)x(index), (qreal)y(x(index)));
|
||||
}
|
||||
|
||||
virtual double y(double x) const
|
||||
{
|
||||
return mData[(int)x];
|
||||
}
|
||||
|
||||
virtual double x( uint index ) const
|
||||
{
|
||||
return (index >= 0 && index < size() ? index : 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
QVector<quint32> mData;
|
||||
double mMaxValue; //if zero do not normalize Y to scale of mMaxValue
|
||||
double mOffset;
|
||||
};
|
||||
|
||||
|
||||
Histogram::Histogram(const char* name, int maxValueX, QWidget *parent): QwtPlot(parent),
|
||||
m_Mono(NULL),
|
||||
m_Red(NULL),
|
||||
m_Green(NULL),
|
||||
m_Blue(NULL),
|
||||
m_MonoCurve(NULL),
|
||||
m_RedCurve(NULL),
|
||||
m_GreenCurve(NULL),
|
||||
m_BlueCurve(NULL),
|
||||
m_YCurve(NULL),
|
||||
m_UCurve(NULL),
|
||||
m_VCurve(NULL),
|
||||
m_Y(NULL),
|
||||
m_U(NULL),
|
||||
m_V(NULL),
|
||||
m_MaxValueX(maxValueX),
|
||||
m_MaxValueY(0),
|
||||
m_dYAxisMaximum(0)
|
||||
{
|
||||
setAutoReplot(false);
|
||||
|
||||
// panning with the left mouse button
|
||||
(void) new QwtPlotPanner( canvas() );
|
||||
|
||||
// zoom in/out with the wheel
|
||||
(void) new QwtPlotMagnifier( canvas() );
|
||||
|
||||
setAutoFillBackground( true );
|
||||
|
||||
setTitle(name);
|
||||
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
|
||||
|
||||
// grid
|
||||
QwtPlotGrid *grid = new QwtPlotGrid;
|
||||
grid->enableXMin(true);
|
||||
grid->enableYMin(true);
|
||||
grid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine));
|
||||
grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine));
|
||||
grid->attach(this);
|
||||
|
||||
// axes
|
||||
//setAxisScale(xBottom, 0.0, mMaxValueX);
|
||||
//setAxisScale(yLeft, 0.0, 1400000.0);
|
||||
setAxisAutoScale(xBottom, true);
|
||||
setAxisAutoScale(yLeft, true);
|
||||
|
||||
//// canvas
|
||||
QwtPlotCanvas *plotCanvas = new QwtPlotCanvas();
|
||||
plotCanvas->setBorderRadius( 5 );
|
||||
plotCanvas->setLineWidth(1);
|
||||
plotCanvas->setFrameStyle(QFrame::Box | QFrame::Plain );
|
||||
setCanvas(plotCanvas);
|
||||
|
||||
QPalette canvasPalette( Qt::white );
|
||||
canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
|
||||
canvas()->setPalette( canvasPalette );
|
||||
|
||||
// Insert new curves
|
||||
QPen penMono(Qt::black);
|
||||
penMono.setWidth(2);
|
||||
m_MonoCurve = new QwtPlotCurve(tr("mono"));
|
||||
m_MonoCurve->setStyle(QwtPlotCurve::Lines);
|
||||
//m_MonoCurve->setBrush(Qt::black);
|
||||
m_MonoCurve->setPen(penMono);
|
||||
m_MonoCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_MonoCurve->attach(this);
|
||||
|
||||
QPen penRed(Qt::red);
|
||||
penRed.setWidth(2);
|
||||
m_RedCurve = new QwtPlotCurve(tr("red"));
|
||||
//m_RedCurve->setBrush(Qt::red);
|
||||
m_RedCurve->setStyle(QwtPlotCurve::Lines);
|
||||
m_RedCurve->setPen(penRed);
|
||||
m_RedCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_RedCurve->attach(this);
|
||||
|
||||
QPen penGreen(Qt::green);
|
||||
penGreen.setWidth(2);
|
||||
m_GreenCurve = new QwtPlotCurve(tr("green"));
|
||||
//m_GreenCurve->setBrush(Qt::green);
|
||||
m_GreenCurve->setStyle(QwtPlotCurve::Lines);
|
||||
m_GreenCurve->setPen(penGreen);
|
||||
m_GreenCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_GreenCurve->attach(this);
|
||||
|
||||
QPen penBlue(Qt::blue);
|
||||
penBlue.setWidth(2);
|
||||
m_BlueCurve = new QwtPlotCurve(tr("blue"));
|
||||
//m_BlueCurve->setBrush(Qt::blue);
|
||||
m_BlueCurve->setStyle(QwtPlotCurve::Lines);
|
||||
m_BlueCurve->setPen(penBlue);
|
||||
m_BlueCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_BlueCurve->attach(this);
|
||||
|
||||
QPen penYellow(Qt::darkYellow);
|
||||
penYellow.setWidth(2);
|
||||
m_YCurve = new QwtPlotCurve(tr("Y"));
|
||||
//m_YCurve->setBrush(Qt::darkYellow);
|
||||
m_YCurve->setStyle(QwtPlotCurve::Lines);
|
||||
m_YCurve->setPen(penYellow);
|
||||
m_YCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_YCurve->attach(this);
|
||||
|
||||
QPen penCyan(Qt::darkCyan);
|
||||
penCyan.setWidth(2);
|
||||
m_UCurve = new QwtPlotCurve(tr("U"));
|
||||
//m_UCurve->setBrush(Qt::darkCyan);
|
||||
m_UCurve->setStyle(QwtPlotCurve::Lines);
|
||||
m_UCurve->setPen(penCyan);
|
||||
m_UCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_UCurve->attach(this);
|
||||
|
||||
QPen penMagenta(Qt::darkMagenta);
|
||||
penMagenta.setWidth(2);
|
||||
m_VCurve = new QwtPlotCurve(tr("V"));
|
||||
//m_VCurve->setBrush(Qt::darkMagenta);
|
||||
m_VCurve->setStyle(QwtPlotCurve::Lines);
|
||||
m_VCurve->setPen(penMagenta);
|
||||
m_VCurve->setYAxis(QwtPlot::yLeft);
|
||||
m_VCurve->attach(this);
|
||||
|
||||
// picker
|
||||
m_PlotPicker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas());
|
||||
m_PlotPicker->setStateMachine(new QwtPickerDragPointMachine());
|
||||
m_PlotPicker->setRubberBandPen(QColor( 128, 0, 0 ));
|
||||
m_PlotPicker->setRubberBand(QwtPicker::CrossRubberBand);
|
||||
m_PlotPicker->setTrackerPen(QColor( 128, 0, 0 ));
|
||||
|
||||
setAutoReplot(true);
|
||||
}
|
||||
|
||||
Histogram::~Histogram()
|
||||
{
|
||||
}
|
||||
|
||||
void Histogram::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QwtPlot::resizeEvent( event );
|
||||
}
|
||||
|
||||
void Histogram::populate( const QVector<quint32> &histogramData, const QString &sColorComponent )
|
||||
{
|
||||
const bool doReplot = autoReplot();
|
||||
setAutoReplot(false);
|
||||
|
||||
if( 0 == sColorComponent.compare("M") )
|
||||
{
|
||||
m_Mono = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_MonoCurve->setData(m_Mono);
|
||||
}
|
||||
|
||||
if( 0 == sColorComponent.compare("R") )
|
||||
{
|
||||
m_Red = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_RedCurve->setData(m_Red);
|
||||
}
|
||||
|
||||
if( 0 == sColorComponent.compare("G") )
|
||||
{
|
||||
m_Green = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_GreenCurve->setData(m_Green);
|
||||
}
|
||||
|
||||
if( 0 == sColorComponent.compare("B") )
|
||||
{
|
||||
m_Blue = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_BlueCurve->setData(m_Blue);
|
||||
}
|
||||
|
||||
if( 0 == sColorComponent.compare("Y") )
|
||||
{
|
||||
m_Y = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_YCurve->setData(m_Y);
|
||||
}
|
||||
|
||||
if( 0 == sColorComponent.compare("U") )
|
||||
{
|
||||
m_U = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_UCurve->setData(m_U);
|
||||
}
|
||||
|
||||
if( 0 == sColorComponent.compare("V") )
|
||||
{
|
||||
m_V = new HistogramSource(histogramData, m_dYAxisMaximum, 0);
|
||||
m_VCurve->setData(m_V);
|
||||
}
|
||||
|
||||
setAutoReplot(doReplot);
|
||||
replot();
|
||||
}
|
||||
|
||||
void Histogram::setHistogramTitle ( const QString &sTitle )
|
||||
{
|
||||
setTitle (sTitle);
|
||||
}
|
||||
|
||||
void Histogram::setLeftAxisY ( const double &dMaximum )
|
||||
{
|
||||
//reset pen
|
||||
QPen penBlack(Qt::black);
|
||||
penBlack.setWidth(1);
|
||||
m_MonoCurve->setPen(penBlack);
|
||||
m_RedCurve->setPen(penBlack);
|
||||
m_GreenCurve->setPen(penBlack);
|
||||
m_BlueCurve->setPen(penBlack);
|
||||
setAxisScale(yLeft, 0.0, dMaximum );
|
||||
m_dYAxisMaximum = dMaximum;
|
||||
}
|
||||
|
||||
void Histogram::setBottomAxisX ( const double &dMaximum )
|
||||
{
|
||||
//set pen to default
|
||||
QPen penBlack(Qt::black);
|
||||
penBlack.setWidth(2);
|
||||
m_MonoCurve->setPen(penBlack);
|
||||
|
||||
QPen penRed(Qt::red);
|
||||
penRed.setWidth(2);
|
||||
m_RedCurve->setPen(penRed);
|
||||
|
||||
QPen penGreen(Qt::green);
|
||||
penGreen.setWidth(2);
|
||||
m_GreenCurve->setPen(penGreen);
|
||||
|
||||
QPen penBlue(Qt::blue);
|
||||
penBlue.setWidth(2);
|
||||
m_BlueCurve->setPen(penBlue);
|
||||
|
||||
setAxisScale(xBottom, 0.0, dMaximum );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: Histogram.cpp
|
||||
|
||||
Description: populate histogram
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
[program/widget] is based in part on the work of
|
||||
the Qwt project (http://qwt.sf.net).
|
||||
=============================================================================*/
|
||||
#ifndef HISTOGRAM_H
|
||||
#define HISTOGRAM_H
|
||||
|
||||
#include "../ExternLib/qwt/qwt_plot.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_curve.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_marker.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_picker.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_renderer.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_grid.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_picker.h"
|
||||
#include "../ExternLib/qwt/qwt_legend.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_panner.h"
|
||||
#include "../ExternLib/qwt/qwt_plot_magnifier.h"
|
||||
#include "../ExternLib/qwt/qwt_picker_machine.h"
|
||||
|
||||
|
||||
#include "../ExternLib/qwt/qwt_slider.h"
|
||||
|
||||
class HistogramSource;
|
||||
|
||||
class Histogram : public QwtPlot
|
||||
{
|
||||
public:
|
||||
explicit Histogram(const char* name, int maxValue, QWidget *parent = 0);
|
||||
~Histogram();
|
||||
|
||||
void populate ( const QVector<quint32> &histogramData, const QString &sColorComponent );
|
||||
void setHistogramTitle ( const QString &sTitle );
|
||||
void setLeftAxisY ( const double &dMaximum );
|
||||
void setBottomAxisX ( const double &dMaximum );
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent( QResizeEvent * );
|
||||
|
||||
private:
|
||||
HistogramSource *m_Mono;
|
||||
HistogramSource *m_Red;
|
||||
HistogramSource *m_Green;
|
||||
HistogramSource *m_Blue;
|
||||
HistogramSource *m_Y;
|
||||
HistogramSource *m_U;
|
||||
HistogramSource *m_V;
|
||||
|
||||
QwtPlotCurve *m_MonoCurve;
|
||||
QwtPlotCurve *m_RedCurve;
|
||||
QwtPlotCurve *m_GreenCurve;
|
||||
QwtPlotCurve *m_BlueCurve;
|
||||
|
||||
QwtPlotCurve *m_YCurve;
|
||||
QwtPlotCurve *m_UCurve;
|
||||
QwtPlotCurve *m_VCurve;
|
||||
|
||||
QwtPlotPicker *m_PlotPicker;
|
||||
|
||||
quint32 m_MaxValueX;
|
||||
quint32 m_MaxValueY;
|
||||
double m_dYAxisMaximum;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
#endif // HISTOGRAM_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,97 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: HistogramThread.h
|
||||
|
||||
Description: a worker thread to process histogram data
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
|
||||
#ifndef HISTOGRAMTHREAD_H
|
||||
#define HISTOGRAMTHREAD_H
|
||||
|
||||
#include <QTime>
|
||||
#include <QThread>
|
||||
#include <QVector>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <qwaitcondition.h>
|
||||
#include "Helper.h"
|
||||
|
||||
#include <VimbaCPP/Include/IFrameObserver.h>
|
||||
#include <VimbaCPP/Include/Frame.h>
|
||||
#include <VimbaCPP/Include/Camera.h>
|
||||
|
||||
|
||||
class HistogramThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
typedef QSharedPointer<unsigned char> data_storage;
|
||||
public:
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
struct statistics
|
||||
{
|
||||
typedef T value_type;
|
||||
T Min;
|
||||
T Max;
|
||||
T Mean;
|
||||
};
|
||||
ConsumerQueue<tFrameInfo> m_FrameInfo;
|
||||
QMutex m_Lock;
|
||||
bool m_Stopping;
|
||||
public:
|
||||
HistogramThread ( );
|
||||
~HistogramThread ( void );
|
||||
|
||||
void stopProcessing();
|
||||
void setThreadFrame ( const tFrameInfo &info );
|
||||
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
void histogramMono8 ( const tFrameInfo &info );
|
||||
void histogramRGB8 ( const tFrameInfo &info );
|
||||
void histogramBGR8 ( const tFrameInfo &info );
|
||||
void histogramYUV411 ( const tFrameInfo &info );
|
||||
void histogramYUV422 ( const tFrameInfo &info );
|
||||
void histogramYUV444 ( const tFrameInfo &info );
|
||||
void histogramNotSupportedYet ( const tFrameInfo &info );
|
||||
void histogramBayerRG12Packed ( const tFrameInfo &info );
|
||||
void histogramBayerRG8 ( const tFrameInfo &info );
|
||||
void histogramBayerRG12 ( const tFrameInfo &info );
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
statistics<T> calcWeightedMean( const QVector<VmbUint32_t>& rValues );
|
||||
|
||||
signals:
|
||||
void histogramDataFromThread ( const QVector<QVector <quint32> > &histData,
|
||||
const QString &sHistogramTitle,
|
||||
const double &nMaxHeight_YAxis,
|
||||
const double &nMaxWidth_XAxis,
|
||||
const QVector <QStringList> &statistics);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,365 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: HistogramWindow.cpp
|
||||
|
||||
Description: Histogram Window
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
[program/widget] is based in part on the work of
|
||||
the Qwt project (http://qwt.sf.net).
|
||||
=============================================================================*/
|
||||
|
||||
|
||||
#include "HistogramWindow.h"
|
||||
#include "Histogram.h"
|
||||
|
||||
HistogramWindow::HistogramWindow(QWidget *parent) :
|
||||
QWidget(parent), m_Histogram ( NULL ), m_StatisticsTable ( NULL ), m_nXAxisMax ( 0 )
|
||||
{
|
||||
m_DataLayout = new QGridLayout();
|
||||
QHBoxLayout *layoutHorizontal = new QHBoxLayout();
|
||||
m_DataLayout->addLayout(layoutHorizontal,0,0);
|
||||
setLayout(m_DataLayout);
|
||||
|
||||
QIcon printIcon;
|
||||
printIcon.addFile( QString::fromUtf8(":/VimbaViewer/Images/print.png"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
m_PrintButton = new QToolButton( this );
|
||||
m_PrintButton->setIcon(printIcon);
|
||||
m_PrintButton->setIconSize(QSize(32,32));
|
||||
m_PrintButton->setToolTip(tr("Print the histogram"));
|
||||
m_PrintButton->setCursor(Qt::PointingHandCursor);
|
||||
m_PrintButton->setStyleSheet(QString::fromUtf8("QToolButton{background-color: rgb(128, 0, 0);} QToolTip {}"));
|
||||
layoutHorizontal->addWidget(m_PrintButton);
|
||||
|
||||
QIcon pdfIcon;
|
||||
pdfIcon.addFile( QString::fromUtf8(":/VimbaViewer/Images/pdf.png"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
m_ExportButton = new QToolButton( this );
|
||||
m_ExportButton->setIcon(pdfIcon);
|
||||
m_ExportButton->setIconSize(QSize(32,32));
|
||||
m_ExportButton->setToolTip(tr("Export the histogram to PDF"));
|
||||
m_ExportButton->setCursor(Qt::PointingHandCursor);
|
||||
m_ExportButton->setStyleSheet(QString::fromUtf8("QToolButton{background-color: rgb(128, 0, 0);} QToolTip {}"));
|
||||
layoutHorizontal->addWidget(m_ExportButton);
|
||||
|
||||
QObject::connect( m_PrintButton, SIGNAL(clicked()), this, SLOT(onPrint()));
|
||||
QObject::connect( m_ExportButton, SIGNAL(clicked()), this, SLOT(onExport()));
|
||||
}
|
||||
|
||||
HistogramWindow::~HistogramWindow( )
|
||||
{
|
||||
if( NULL != m_Histogram)
|
||||
{
|
||||
delete m_Histogram;
|
||||
m_Histogram = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void HistogramWindow::initializeStatistic ( void )
|
||||
{
|
||||
m_StatisticsTable = new QTableWidget();
|
||||
m_DataLayout->addWidget(m_StatisticsTable);
|
||||
m_StatisticsTable->setColumnCount(4);
|
||||
QStringList sHeader;
|
||||
sHeader << "" << tr("Minimum") << tr("Maximum") << tr("Mean");
|
||||
m_StatisticsTable->setHorizontalHeaderLabels(sHeader);
|
||||
m_StatisticsTable->setFixedHeight(135);
|
||||
m_StatisticsTable->verticalHeader()->setVisible(false);
|
||||
}
|
||||
|
||||
void HistogramWindow::deinitializeStatistic ( void )
|
||||
{
|
||||
if(0 != m_StatisticsTable)
|
||||
{
|
||||
delete m_StatisticsTable;
|
||||
m_StatisticsTable = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void HistogramWindow::setStatistic ( const QStringList component,
|
||||
const QStringList minimum,
|
||||
const QStringList maximum,
|
||||
const QStringList average,
|
||||
const QString sFormat )
|
||||
{
|
||||
m_StatisticsTable->clearContents();
|
||||
m_StatisticsTable->setRowCount(component.size());
|
||||
for(int i=0; i < component.size(); i++) /* component */
|
||||
{
|
||||
QTableWidgetItem *item = new QTableWidgetItem();
|
||||
item->setText(component.at(i));
|
||||
|
||||
/* Mono 8 */
|
||||
if(1 == component.size())
|
||||
{
|
||||
item->setBackgroundColor(Qt::black);
|
||||
item->setForeground(QBrush(QColor(255,255,255)));
|
||||
}
|
||||
|
||||
/* RGB, YUV */
|
||||
if(3 == component.size())
|
||||
{
|
||||
if (0 == sFormat.compare("RGB")|| sFormat.contains("Bayer"))
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
item->setBackgroundColor(Qt::red);
|
||||
break;
|
||||
case 1:
|
||||
item->setBackgroundColor(Qt::green);
|
||||
break;
|
||||
case 2:
|
||||
item->setForeground(QBrush(QColor(255,255,255)));
|
||||
item->setBackgroundColor(Qt::blue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(0 == sFormat.compare("YUV"))
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
item->setBackgroundColor(Qt::darkYellow);
|
||||
break;
|
||||
case 1:
|
||||
item->setBackgroundColor(Qt::darkCyan);
|
||||
break;
|
||||
case 2:
|
||||
//item->setForeground(QBrush(QColor(255,255,255)));
|
||||
item->setBackgroundColor(Qt::darkMagenta);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
m_StatisticsTable->setItem(i, 0, item);
|
||||
}
|
||||
|
||||
for(int j=0; j < minimum.size(); j++) /* minimum */
|
||||
{
|
||||
QTableWidgetItem *item = new QTableWidgetItem();
|
||||
item->setText(minimum.at(j));
|
||||
m_StatisticsTable->setItem(j, 1, item);
|
||||
}
|
||||
|
||||
for(int k=0; k < maximum.size(); k++) /* maximum */
|
||||
{
|
||||
QTableWidgetItem *item = new QTableWidgetItem();
|
||||
item->setText(maximum.at(k));
|
||||
m_StatisticsTable->setItem(k, 2, item);
|
||||
}
|
||||
|
||||
for(int l=0; l < average.size(); l++) /* average */
|
||||
{
|
||||
QTableWidgetItem *item = new QTableWidgetItem();
|
||||
item->setText(average.at(l));
|
||||
m_StatisticsTable->setItem(l, 3, item);
|
||||
}
|
||||
}
|
||||
|
||||
void HistogramWindow::createGraphWidgets ( void )
|
||||
{
|
||||
m_Histogram = new Histogram(" ", 255, this); //255: Default
|
||||
m_DataLayout->addWidget(m_Histogram, 2, 0);
|
||||
m_AutoScaleYAxis = new QCheckBox();
|
||||
m_AutoScaleYAxis->setText(tr("Auto scale Y-AXIS ON"));
|
||||
m_AutoScaleYAxis->setChecked(true);
|
||||
m_DataLayout->addWidget(m_AutoScaleYAxis);
|
||||
connect( m_AutoScaleYAxis, SIGNAL(clicked(bool)), this, SLOT(onAutoScaleYAxisClick(bool)) );
|
||||
m_Histogram->installEventFilter(this);
|
||||
}
|
||||
|
||||
void HistogramWindow::onAutoScaleYAxisClick ( bool bValue )
|
||||
{
|
||||
if(bValue)
|
||||
{
|
||||
m_Histogram->setAxisAutoScale(0, true);
|
||||
m_Histogram->setAxisAutoScale(2, true);
|
||||
m_Histogram->setAxisScale(2, 0.0, m_nXAxisMax );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Histogram->setAxisAutoScale(0, false);
|
||||
m_Histogram->setAxisAutoScale(2, false);
|
||||
}
|
||||
}
|
||||
|
||||
void HistogramWindow::updateHistogram( const QVector<QVector<quint32> > &histogramData, const QString &sNewHistogramTitle,
|
||||
const double &nMaxHeight_YAxis, const double &nMaxWidth_XAxis )
|
||||
{
|
||||
if( 0 != m_sCurrentHistogramTitle.compare(sNewHistogramTitle) )
|
||||
{
|
||||
m_Histogram->setHistogramTitle( sNewHistogramTitle );
|
||||
//m_Histogram->setLeftAxisY(nMaxHeight_YAxis);
|
||||
|
||||
if(m_sCurrentHistogramTitle.contains("Mono"))
|
||||
{
|
||||
QVector <quint32> resetValues(255, 0);
|
||||
m_Histogram->populate(resetValues, "M");
|
||||
}
|
||||
|
||||
if(m_sCurrentHistogramTitle.contains("8"))
|
||||
{
|
||||
QVector <quint32> resetValues(255, 0);
|
||||
m_Histogram->populate(resetValues, "R"); // Red
|
||||
m_Histogram->populate(resetValues, "G"); // Green
|
||||
m_Histogram->populate(resetValues, "B"); // Blue
|
||||
}
|
||||
|
||||
if( m_sCurrentHistogramTitle.contains("BayerRG12"))
|
||||
{
|
||||
QVector <quint32> resetValues(4095, 0);
|
||||
m_Histogram->populate(resetValues, "R"); // Red
|
||||
m_Histogram->populate(resetValues, "G"); // Green
|
||||
m_Histogram->populate(resetValues, "B"); // Blue
|
||||
}
|
||||
|
||||
if(m_sCurrentHistogramTitle.contains("YUV"))
|
||||
{
|
||||
QVector <quint32> resetValues(255, 0);
|
||||
m_Histogram->populate(resetValues, "Y"); // Y
|
||||
m_Histogram->populate(resetValues, "U"); // U
|
||||
m_Histogram->populate(resetValues, "V"); // V
|
||||
}
|
||||
|
||||
m_Histogram->setBottomAxisX(nMaxWidth_XAxis);
|
||||
m_nXAxisMax = nMaxWidth_XAxis;
|
||||
m_sCurrentHistogramTitle = sNewHistogramTitle;
|
||||
}
|
||||
|
||||
if( 1 == histogramData.size() && (m_sCurrentHistogramTitle.contains("Mono"))) // 1 color component -> Mono
|
||||
m_Histogram->populate(histogramData.at(0), "M");
|
||||
|
||||
if( 3 == histogramData.size() && m_sCurrentHistogramTitle.contains("RGB8") ||
|
||||
3 == histogramData.size() && m_sCurrentHistogramTitle.contains("BGR8") ||
|
||||
m_sCurrentHistogramTitle.contains("Bayer") ) // 3 color components -> R,G,B
|
||||
{
|
||||
m_Histogram->populate(histogramData.at(0), "R"); // Red
|
||||
m_Histogram->populate(histogramData.at(1), "G"); // Green
|
||||
m_Histogram->populate(histogramData.at(2), "B"); // Blue
|
||||
}
|
||||
|
||||
if( 3 == histogramData.size() && m_sCurrentHistogramTitle.contains("YUV") ) // 3 color components -> Y,U,V
|
||||
{
|
||||
m_Histogram->populate(histogramData.at(0), "Y"); // Y
|
||||
m_Histogram->populate(histogramData.at(1), "U"); // U
|
||||
m_Histogram->populate(histogramData.at(2), "V"); // V
|
||||
}
|
||||
|
||||
/*if( m_sCurrentHistogramTitle.contains("Not Supported Yet") )
|
||||
m_Histogram->populate(histogramData.at(0), "M");*/
|
||||
}
|
||||
|
||||
void HistogramWindow::onPrint ( void )
|
||||
{
|
||||
#ifndef QT_NO_PRINTER
|
||||
|
||||
QPrinter printer( QPrinter::HighResolution );
|
||||
|
||||
QString docName = m_Histogram->title().text();
|
||||
if ( !docName.isEmpty() )
|
||||
{
|
||||
docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) );
|
||||
printer.setDocName ( docName );
|
||||
}
|
||||
|
||||
printer.setCreator( "Histogram" );
|
||||
printer.setOrientation( QPrinter::Landscape );
|
||||
|
||||
QPrintDialog dialog( &printer );
|
||||
if ( dialog.exec() )
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
|
||||
if ( printer.colorMode() == QPrinter::GrayScale )
|
||||
{
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
|
||||
renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
|
||||
}
|
||||
|
||||
renderer.renderTo( m_Histogram, printer );
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void HistogramWindow::onExport ( void )
|
||||
{
|
||||
#ifndef QT_NO_PRINTER
|
||||
QString fileName = "Histogram.pdf";
|
||||
#else
|
||||
QString fileName = "Histogram.png";
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_FILEDIALOG
|
||||
const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();
|
||||
|
||||
QStringList filter;
|
||||
filter += "PDF Documents (*.pdf)";
|
||||
|
||||
#ifndef QWT_NO_SVG
|
||||
filter += "SVG Documents (*.svg)";
|
||||
#endif
|
||||
filter += "Postscript Documents (*.ps)";
|
||||
|
||||
if ( imageFormats.size() > 0 )
|
||||
{
|
||||
QString imageFilter( "Images (" );
|
||||
|
||||
for ( int i = 0; i < imageFormats.size(); i++ )
|
||||
{
|
||||
if ( i > 0 )
|
||||
imageFilter += " ";
|
||||
|
||||
imageFilter += "*.";
|
||||
imageFilter += imageFormats[i];
|
||||
}
|
||||
imageFilter += ")";
|
||||
|
||||
filter += imageFilter;
|
||||
}
|
||||
|
||||
fileName = QFileDialog::getSaveFileName( this, "Export File Name", fileName,
|
||||
filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
|
||||
#endif
|
||||
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
QwtPlotRenderer renderer;
|
||||
renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, false );
|
||||
renderer.renderDocument( m_Histogram, fileName, QSizeF( 300, 200 ), 85 );
|
||||
}
|
||||
}
|
||||
|
||||
bool HistogramWindow::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Wheel)
|
||||
{
|
||||
m_AutoScaleYAxis->setChecked(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: HistogramWindow.h
|
||||
|
||||
Description: Histogram Window
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
[program/widget] is based in part on the work of
|
||||
the Qwt project (http://qwt.sf.net).
|
||||
=============================================================================*/
|
||||
|
||||
|
||||
#ifndef HISTOGRAMWINDOW_H
|
||||
#define HISTOGRAMWINDOW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QToolButton>
|
||||
#include <QImageWriter>
|
||||
#include <QFileDialog>
|
||||
#include <QPrinter>
|
||||
#include <QPrintDialog>
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QEvent>
|
||||
#include <QCheckBox>
|
||||
|
||||
class Histogram;
|
||||
|
||||
class HistogramWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HistogramWindow(QWidget *parent = 0);
|
||||
~HistogramWindow();
|
||||
|
||||
void createGraphWidgets ( void );
|
||||
void initializeStatistic ( void );
|
||||
void deinitializeStatistic ( void );
|
||||
void setStatistic ( const QStringList component, const QStringList minimum, const QStringList maximum, const QStringList average, const QString sFormat );
|
||||
|
||||
private:
|
||||
|
||||
QToolButton *m_PrintButton;
|
||||
QToolButton *m_ExportButton;
|
||||
QGridLayout *m_DataLayout;
|
||||
Histogram *m_Histogram;
|
||||
QString m_sCurrentHistogramTitle;
|
||||
QTableWidget *m_StatisticsTable;
|
||||
QCheckBox *m_AutoScaleYAxis;
|
||||
unsigned int m_nXAxisMax;
|
||||
bool eventFilter (QObject *object, QEvent *event);
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
void onPrint ( void );
|
||||
void onExport ( void );
|
||||
|
||||
public slots:
|
||||
void updateHistogram( const QVector<QVector<quint32> > &histogramData, const QString &sNewHistogramTitle,
|
||||
const double &nMaxHeight_YAxis, const double &nMaxWidth_XAxis );
|
||||
void onAutoScaleYAxisClick ( bool bValue );
|
||||
|
||||
};
|
||||
|
||||
#endif // HISTOGRAMWINDOW_H
|
||||
Reference in New Issue
Block a user