Skip to content

Commit

Permalink
Trying to immprove UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkonrom committed Oct 2, 2017
1 parent 0d1dce9 commit 8716faf
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 195 deletions.
264 changes: 132 additions & 132 deletions boundaries.cpp
Original file line number Diff line number Diff line change
@@ -1,149 +1,149 @@
#include "boundaries.h"
#include <QDebug>



Boundaries::Boundaries()
{

}

inline Mat Boundaries::QImageToCvMat( const QImage &inImage, bool inCloneImageData)
{
switch ( inImage.format() )
{
// 8-bit, 4 channel
case QImage::Format_ARGB32:
case QImage::Format_ARGB32_Premultiplied:
{
cv::Mat mat( inImage.height(), inImage.width(),
CV_8UC4,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);

return (inCloneImageData ? mat.clone() : mat);
}

// 8-bit, 3 channel
case QImage::Format_RGB32:
case QImage::Format_RGB888:
{
if ( !inCloneImageData )
{
qWarning() << "ASM::QImageToCvMat() - Conversion requires cloning because we use a temporary QImage";
}

QImage swapped = inImage;

if ( inImage.format() == QImage::Format_RGB32 )
{
swapped = swapped.convertToFormat( QImage::Format_RGB888 );
}

swapped = swapped.rgbSwapped();

return cv::Mat( swapped.height(), swapped.width(),
CV_8UC3,
const_cast<uchar*>(swapped.bits()),
static_cast<size_t>(swapped.bytesPerLine())
).clone();
}

// 8-bit, 1 channel
case QImage::Format_Indexed8:
{
cv::Mat mat( inImage.height(), inImage.width(),
CV_8UC1,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);

return (inCloneImageData ? mat.clone() : mat);
}

default:
qWarning() << "ASM::QImageToCvMat() - QImage format not handled in switch:" << inImage.format();
break;
}

return cv::Mat();
}

inline QImage Boundaries::cvMatToQImage( const cv::Mat &inMat )
{
switch ( inMat.type() )
{
// 8-bit, 4 channel
case CV_8UC4:
{
QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_ARGB32 );
#include "boundaries.h"
#include <QDebug>

return image;
}

// 8-bit, 3 channel
case CV_8UC3:
{
QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_RGB888 );

return image.rgbSwapped();
}
Boundaries::Boundaries()
{

// 8-bit, 1 channel
case CV_8UC1:
}

inline Mat Boundaries::QImageToCvMat( const QImage &inImage, bool inCloneImageData)
{
switch ( inImage.format() )
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_Grayscale8 );
#else
static QVector<QRgb> sColorTable;

// only create our color table the first time
if ( sColorTable.isEmpty() )
// 8-bit, 4 channel
case QImage::Format_ARGB32:
case QImage::Format_ARGB32_Premultiplied:
{
cv::Mat mat( inImage.height(), inImage.width(),
CV_8UC4,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);

return (inCloneImageData ? mat.clone() : mat);
}

// 8-bit, 3 channel
case QImage::Format_RGB32:
case QImage::Format_RGB888:
{
sColorTable.resize( 256 );
if ( !inCloneImageData )
{
qWarning() << "ASM::QImageToCvMat() - Conversion requires cloning because we use a temporary QImage";
}

QImage swapped = inImage;

for ( int i = 0; i < 256; ++i )
if ( inImage.format() == QImage::Format_RGB32 )
{
sColorTable[i] = qRgb( i, i, i );
swapped = swapped.convertToFormat( QImage::Format_RGB888 );
}

swapped = swapped.rgbSwapped();

return cv::Mat( swapped.height(), swapped.width(),
CV_8UC3,
const_cast<uchar*>(swapped.bits()),
static_cast<size_t>(swapped.bytesPerLine())
).clone();
}

QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_Indexed8 );
// 8-bit, 1 channel
case QImage::Format_Indexed8:
{
cv::Mat mat( inImage.height(), inImage.width(),
CV_8UC1,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);

image.setColorTable( sColorTable );
#endif
return (inCloneImageData ? mat.clone() : mat);
}

return image;
default:
qWarning() << "ASM::QImageToCvMat() - QImage format not handled in switch:" << inImage.format();
break;
}

default:
qWarning() << "ASM::cvMatToQImage() - cv::Mat image type not handled in switch:" << inMat.type();
break;
return cv::Mat();
}

return QImage();
}

QImage Boundaries::execute(int value){
inputMat = QImageToCvMat(inputImage, true);
this->outputMap.create(inputMat.size(), inputMat.type());
cvtColor(inputMat, inputMatGrayScaled, CV_BGR2GRAY);
blur(inputMatGrayScaled, detectedEdges, Size(3,3));
Canny(detectedEdges, detectedEdges, value, value*ratio, kernelSize);
outputMap = Scalar::all(0);
inputMat.copyTo(outputMap, detectedEdges);
return cvMatToQImage(outputMap);
}
inline QImage Boundaries::cvMatToQImage( const cv::Mat &inMat )
{
switch ( inMat.type() )
{
// 8-bit, 4 channel
case CV_8UC4:
{
QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_ARGB32 );

return image;
}

// 8-bit, 3 channel
case CV_8UC3:
{
QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_RGB888 );

return image.rgbSwapped();
}

// 8-bit, 1 channel
case CV_8UC1:
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_Grayscale8 );
#else
static QVector<QRgb> sColorTable;

// only create our color table the first time
if ( sColorTable.isEmpty() )
{
sColorTable.resize( 256 );

for ( int i = 0; i < 256; ++i )
{
sColorTable[i] = qRgb( i, i, i );
}
}

QImage image( inMat.data,
inMat.cols, inMat.rows,
static_cast<int>(inMat.step),
QImage::Format_Indexed8 );

image.setColorTable( sColorTable );
#endif

return image;
}

default:
qWarning() << "ASM::cvMatToQImage() - cv::Mat image type not handled in switch:" << inMat.type();
break;
}

return QImage();
}

QImage Boundaries::execute(int value){
inputMat = QImageToCvMat(inputImage, true);
this->outputMap.create(inputMat.size(), inputMat.type());
cvtColor(inputMat, inputMatGrayScaled, CV_BGR2GRAY);
blur(inputMatGrayScaled, detectedEdges, Size(3,3));
Canny(detectedEdges, detectedEdges, value, value*ratio, kernelSize);
outputMap = Scalar::all(0);
inputMat.copyTo(outputMap, detectedEdges);
return cvMatToQImage(outputMap);
}
86 changes: 23 additions & 63 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -146,68 +146,6 @@
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="options_layout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>248</height>
</size>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QSlider" name="horizontalSlider">
<property name="geometry">
<rect>
<x>-20</x>
<y>50</y>
<width>84</width>
<height>15</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -235,6 +173,28 @@
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 8716faf

Please sign in to comment.