mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 00:40:06 +02:00
Can copy an image using ITK.
This commit is contained in:
parent
861c33d5a9
commit
b13ccab303
6 changed files with 89 additions and 29 deletions
37
tools/auto-tester/src/ITKImageComparer.cpp
Normal file
37
tools/auto-tester/src/ITKImageComparer.cpp
Normal file
|
@ -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 <itkRGBPixel.h>
|
||||||
|
#include <itkImage.h>
|
||||||
|
#include <itkImageFileReader.h>
|
||||||
|
#include <itkImageFileWriter.h>
|
||||||
|
|
||||||
|
float ITKImageComparer::compareImages(QString file1, QString file2) const {
|
||||||
|
using PixelType = itk::RGBPixel<unsigned char>;
|
||||||
|
using ImageType = itk::Image<PixelType, 2>;
|
||||||
|
|
||||||
|
using ReaderType = itk::ImageFileReader<ImageType>;
|
||||||
|
using WriterType = itk::ImageFileWriter<ImageType>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
22
tools/auto-tester/src/ITKImageComparer.h
Normal file
22
tools/auto-tester/src/ITKImageComparer.h
Normal file
|
@ -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 <itkImage.h>
|
||||||
|
|
||||||
|
class ITKImageComparer : public ImageComparer {
|
||||||
|
public:
|
||||||
|
float compareImages(QString file1, QString file2) const final;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ITKImageComparer_h
|
20
tools/auto-tester/src/ImageComparer.h
Normal file
20
tools/auto-tester/src/ImageComparer.h
Normal file
|
@ -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 <QtCore/QString>
|
||||||
|
|
||||||
|
class ImageComparer {
|
||||||
|
public:
|
||||||
|
virtual float compareImages(QString file1, QString file2) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_ImageComparer_h
|
|
@ -46,13 +46,13 @@ void Test::evaluateTests() {
|
||||||
// Separate images into two lists. The first is the expected images, the second is the test results
|
// 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.
|
// Images that are in the wrong format are ignored.
|
||||||
QStringList expectedImages;
|
QStringList expectedImages;
|
||||||
QStringList resultImages;
|
QStringList actualImages;
|
||||||
foreach(QString currentFilename, sortedImageFilenames) {
|
foreach(QString currentFilename, sortedImageFilenames) {
|
||||||
QString fullCurrentFilename = pathToImageDirectory + "/" + currentFilename;
|
QString fullCurrentFilename = pathToImageDirectory + "/" + currentFilename;
|
||||||
if (isInExpectedImageFilenameFormat(currentFilename)) {
|
if (isInExpectedImageFilenameFormat(currentFilename)) {
|
||||||
expectedImages << fullCurrentFilename;
|
expectedImages << fullCurrentFilename;
|
||||||
} else if (isInSnapshotFilenameFormat(currentFilename)) {
|
} else if (isInSnapshotFilenameFormat(currentFilename)) {
|
||||||
resultImages << fullCurrentFilename;
|
actualImages << fullCurrentFilename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,32 +72,13 @@ void Test::evaluateTests() {
|
||||||
bool success{ true };
|
bool success{ true };
|
||||||
bool keepOn{ true };
|
bool keepOn{ true };
|
||||||
for (int i = 0; keepOn && i < expectedImages.length(); ++i) {
|
for (int i = 0; keepOn && i < expectedImages.length(); ++i) {
|
||||||
////QString diffFilename = "HIFI_AutoTest_diff.txt";
|
float error = itkImageComparer.compareImages(expectedImages[i], actualImages[i]);
|
||||||
////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]);
|
|
||||||
if (error > THRESHOLD) {
|
if (error > THRESHOLD) {
|
||||||
mismatchWindow.setTestFailure(TestFailure{
|
mismatchWindow.setTestFailure(TestFailure{
|
||||||
error, // value of the error (float)
|
error, // value of the error (float)
|
||||||
expectedImages[i].left(expectedImages[i].lastIndexOf("/") + 1), // path to the test (including trailing /
|
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(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();
|
mismatchWindow.exec();
|
||||||
|
|
|
@ -14,17 +14,17 @@
|
||||||
|
|
||||||
class TestFailure {
|
class TestFailure {
|
||||||
public:
|
public:
|
||||||
TestFailure(float error, QString pathname, QString expectedImageFilename, QString resultImageFilename) {
|
TestFailure(float error, QString pathname, QString expectedImageFilename, QString actualImageFilename) {
|
||||||
_error = error;
|
_error = error;
|
||||||
_pathname = pathname;
|
_pathname = pathname;
|
||||||
_expectedImageFilename = expectedImageFilename;
|
_expectedImageFilename = expectedImageFilename;
|
||||||
_resultImageFilename = resultImageFilename;
|
_actualImageFilename = actualImageFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
float _error;
|
float _error;
|
||||||
QString _pathname;
|
QString _pathname;
|
||||||
QString _expectedImageFilename;
|
QString _expectedImageFilename;
|
||||||
QString _resultImageFilename;
|
QString _actualImageFilename;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum UserResponse {
|
enum UserResponse {
|
||||||
|
|
|
@ -17,7 +17,7 @@ MismatchWindow::MismatchWindow(QWidget *parent)
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
expectedImage->setScaledContents(true);
|
expectedImage->setScaledContents(true);
|
||||||
resultImage->setScaledContents(true);
|
actualImage->setScaledContents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MismatchWindow::setTestFailure(TestFailure testFailure) {
|
void MismatchWindow::setTestFailure(TestFailure testFailure) {
|
||||||
|
@ -28,8 +28,8 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) {
|
||||||
expectedFilename->setText(testFailure._expectedImageFilename);
|
expectedFilename->setText(testFailure._expectedImageFilename);
|
||||||
expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename));
|
expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename));
|
||||||
|
|
||||||
resultFilename->setText(testFailure._resultImageFilename);
|
actualFilename->setText(testFailure._actualImageFilename);
|
||||||
resultImage->setPixmap(QPixmap(testFailure._pathname + testFailure._resultImageFilename));
|
actualImage->setPixmap(QPixmap(testFailure._pathname + testFailure._actualImageFilename));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MismatchWindow::on_passTestButton_clicked()
|
void MismatchWindow::on_passTestButton_clicked()
|
||||||
|
|
Loading…
Reference in a new issue