From b13ccab303adcdf3dba7335283f3147f5cda0353 Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Mon, 20 Nov 2017 01:24:52 -0800 Subject: [PATCH] Can copy an image using ITK. --- tools/auto-tester/src/ITKImageComparer.cpp | 37 +++++++++++++++++++++ tools/auto-tester/src/ITKImageComparer.h | 22 ++++++++++++ tools/auto-tester/src/ImageComparer.h | 20 +++++++++++ tools/auto-tester/src/Test.cpp | 27 +++------------ tools/auto-tester/src/common.h | 6 ++-- tools/auto-tester/src/ui/MismatchWindow.cpp | 6 ++-- 6 files changed, 89 insertions(+), 29 deletions(-) create mode 100644 tools/auto-tester/src/ITKImageComparer.cpp create mode 100644 tools/auto-tester/src/ITKImageComparer.h create mode 100644 tools/auto-tester/src/ImageComparer.h diff --git a/tools/auto-tester/src/ITKImageComparer.cpp b/tools/auto-tester/src/ITKImageComparer.cpp new file mode 100644 index 0000000000..fd0e71a339 --- /dev/null +++ b/tools/auto-tester/src/ITKImageComparer.cpp @@ -0,0 +1,37 @@ +// +// ITKImageComparer.cpp +// +// Created by Nissim Hadar on 18 Nov 2017. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "ITKImageComparer.h" + +#include +#include +#include +#include + +float ITKImageComparer::compareImages(QString file1, QString file2) const { + using PixelType = itk::RGBPixel; + using ImageType = itk::Image; + + using ReaderType = itk::ImageFileReader; + using WriterType = itk::ImageFileWriter; + + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + reader->SetFileName(file1.toStdString().c_str()); + writer->SetFileName("D:/pics/loni.jpg"); + + ImageType::Pointer image = reader->GetOutput(); + writer->SetInput(image); + + writer->Update(); + + return 0.0; +} diff --git a/tools/auto-tester/src/ITKImageComparer.h b/tools/auto-tester/src/ITKImageComparer.h new file mode 100644 index 0000000000..616bbbfe03 --- /dev/null +++ b/tools/auto-tester/src/ITKImageComparer.h @@ -0,0 +1,22 @@ +// +// ITKImageComparer.h +// +// Created by Nissim Hadar on 18 Nov 2017. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_ITKImageComparer_h +#define hifi_ITKImageComparer_h + +#include "ImageComparer.h" + +#include + +class ITKImageComparer : public ImageComparer { +public: + float compareImages(QString file1, QString file2) const final; +}; + +#endif // hifi_ITKImageComparer_h diff --git a/tools/auto-tester/src/ImageComparer.h b/tools/auto-tester/src/ImageComparer.h new file mode 100644 index 0000000000..c00c8b7e76 --- /dev/null +++ b/tools/auto-tester/src/ImageComparer.h @@ -0,0 +1,20 @@ +// +// ImageComparer.h +// +// Created by Nissim Hadar on 18 Nov 2017. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_ImageComparer_h +#define hifi_ImageComparer_h + +#include + +class ImageComparer { +public: + virtual float compareImages(QString file1, QString file2) const = 0; +}; + +#endif // hifi_ImageComparer_h diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index db42d94391..59511f7c8c 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -46,13 +46,13 @@ void Test::evaluateTests() { // Separate images into two lists. The first is the expected images, the second is the test results // Images that are in the wrong format are ignored. QStringList expectedImages; - QStringList resultImages; + QStringList actualImages; foreach(QString currentFilename, sortedImageFilenames) { QString fullCurrentFilename = pathToImageDirectory + "/" + currentFilename; if (isInExpectedImageFilenameFormat(currentFilename)) { expectedImages << fullCurrentFilename; } else if (isInSnapshotFilenameFormat(currentFilename)) { - resultImages << fullCurrentFilename; + actualImages << fullCurrentFilename; } } @@ -72,32 +72,13 @@ void Test::evaluateTests() { bool success{ true }; bool keepOn{ true }; for (int i = 0; keepOn && i < expectedImages.length(); ++i) { - ////QString diffFilename = "HIFI_AutoTest_diff.txt"; - ////QString command = "magick.exe compare -metric MAE " + expectedImages[i] + " " + resultImages[i] + " null: 2>" + diffFilename; - //// - ////if (system(command.toStdString().c_str()) == -1) { - //// // command has failed - //// messageBox.critical(0, "Aborting!", "Error executing magick.exe"); - //// exit(-1); - ////} - - ////QFile file(diffFilename); - ////if (!file.open(QIODevice::ReadOnly)) { - //// messageBox.critical(0, "Error", file.errorString()); - ////} - - ////// First value on line is the comparison result - ////QTextStream in(&file); - ////QString line = in.readLine(); - ////QStringList tokens = line.split(' '); - ////float error = tokens[0].toFloat(); - float error = itkImageComparer.compareImages(expectedImages[i], resultImages[i]); + float error = itkImageComparer.compareImages(expectedImages[i], actualImages[i]); if (error > THRESHOLD) { mismatchWindow.setTestFailure(TestFailure{ error, // value of the error (float) expectedImages[i].left(expectedImages[i].lastIndexOf("/") + 1), // path to the test (including trailing / QFileInfo(expectedImages[i].toStdString().c_str()).fileName(), // filename of expected image - QFileInfo(resultImages[i].toStdString().c_str()).fileName() // filename of result image + QFileInfo(actualImages[i].toStdString().c_str()).fileName() // filename of result image }); mismatchWindow.exec(); diff --git a/tools/auto-tester/src/common.h b/tools/auto-tester/src/common.h index 1f66466009..079f1d3ebf 100644 --- a/tools/auto-tester/src/common.h +++ b/tools/auto-tester/src/common.h @@ -14,17 +14,17 @@ class TestFailure { public: - TestFailure(float error, QString pathname, QString expectedImageFilename, QString resultImageFilename) { + TestFailure(float error, QString pathname, QString expectedImageFilename, QString actualImageFilename) { _error = error; _pathname = pathname; _expectedImageFilename = expectedImageFilename; - _resultImageFilename = resultImageFilename; + _actualImageFilename = actualImageFilename; } float _error; QString _pathname; QString _expectedImageFilename; - QString _resultImageFilename; + QString _actualImageFilename; }; enum UserResponse { diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index fa1598aad6..1e1d0f91d9 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -17,7 +17,7 @@ MismatchWindow::MismatchWindow(QWidget *parent) setupUi(this); expectedImage->setScaledContents(true); - resultImage->setScaledContents(true); + actualImage->setScaledContents(true); } void MismatchWindow::setTestFailure(TestFailure testFailure) { @@ -28,8 +28,8 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) { expectedFilename->setText(testFailure._expectedImageFilename); expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename)); - resultFilename->setText(testFailure._resultImageFilename); - resultImage->setPixmap(QPixmap(testFailure._pathname + testFailure._resultImageFilename)); + actualFilename->setText(testFailure._actualImageFilename); + actualImage->setPixmap(QPixmap(testFailure._pathname + testFailure._actualImageFilename)); } void MismatchWindow::on_passTestButton_clicked()