One Bug found and changed

This commit is contained in:
JRauer 2018-01-26 22:26:19 +01:00
parent 3a57fbd5e9
commit 1787af11ab
4 changed files with 22 additions and 19 deletions

View File

@ -10,14 +10,15 @@
// k Free parameter of Harris detector // k Free parameter of Harris detector
#include <iostream> #include <iostream>
#include "opencv2/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
using namespace cv; using namespace cv;
using namespace std; using namespace std;
bool AbstractionLayer_SURFFeatures::PreProcessing(coor mySize, const vector<Part*>* partArray) bool AbstractionLayer_SURFFeatures::PreProcessing(coor mySize, const vector<Part*>* partArray)
{ {
cout << "Abstraction 4 (Features) Preprocessing... " << flush;
InitialiseConstraintMatrixSize(mySize.col, mySize.row); InitialiseConstraintMatrixSize(mySize.col, mySize.row);
if(!PreProcessingFullImg(mySize)) return false; if(!PreProcessingFullImg(mySize)) return false;
if(!PreProcessingPieces(mySize, partArray)) return false; if(!PreProcessingPieces(mySize, partArray)) return false;
@ -32,7 +33,7 @@ bool AbstractionLayer_SURFFeatures::EvaluateQuality (coor constraintCoordinate,
{ {
float diff = abs(m_constraintMatrix[constraintCoordinate.row][constraintCoordinate.col].m_numberOfFeaturesDetected - qVector[i].second->m_a4.m_numberOfFeaturesDetected); float diff = abs(m_constraintMatrix[constraintCoordinate.row][constraintCoordinate.col].m_numberOfFeaturesDetected - qVector[i].second->m_a4.m_numberOfFeaturesDetected);
qVector[i].first = 1 - diff; qVector[i].first = 1 - diff;
//cout << fixed << qVector[i].first << " "; //cout << fixed << qVector[i].first << endl;
} }
return true; return true;
@ -42,6 +43,7 @@ bool AbstractionLayer_SURFFeatures::SetConstraintOnPosition(const coor constrain
{ {
//TODO: Benötigen wir nicht unbedint. //TODO: Benötigen wir nicht unbedint.
//TODO: Hier erhalten wir vom Dispatcher welches Teil an welche Position gesetzt wird und wir könnten hier die Features des Bilds in die m_constraintMatrix speichern //TODO: Hier erhalten wir vom Dispatcher welches Teil an welche Position gesetzt wird und wir könnten hier die Features des Bilds in die m_constraintMatrix speichern
return true;
} }
bool AbstractionLayer_SURFFeatures::RemoveConstraintOnPosition(const coor constraintCoordinate) bool AbstractionLayer_SURFFeatures::RemoveConstraintOnPosition(const coor constraintCoordinate)
@ -49,6 +51,7 @@ bool AbstractionLayer_SURFFeatures::RemoveConstraintOnPosition(const coor constr
//TODO: Wie auch beim SetConstraint sollte uns das hier nicht wirklich interessieren. //TODO: Wie auch beim SetConstraint sollte uns das hier nicht wirklich interessieren.
//TODO: Außer wir setzen etwas in die Contraintmatrix. //TODO: Außer wir setzen etwas in die Contraintmatrix.
//TODO: Dann ruft uns der Dispatcher beim Backtrack hier auf und wir müssten das jeweilige PuzzlePart hier wieder rauslöschen. //TODO: Dann ruft uns der Dispatcher beim Backtrack hier auf und wir müssten das jeweilige PuzzlePart hier wieder rauslöschen.
return true;
} }
bool AbstractionLayer_SURFFeatures::PreProcessingFullImg(coor mySize) bool AbstractionLayer_SURFFeatures::PreProcessingFullImg(coor mySize)
@ -56,26 +59,26 @@ bool AbstractionLayer_SURFFeatures::PreProcessingFullImg(coor mySize)
std::vector< cv::Point2f > corners; // Variable to store corner-positions at std::vector< cv::Point2f > corners; // Variable to store corner-positions at
// Load and resize image, so that number of parts in row and col fit in // Load and resize image, so that number of parts in row and col fit in
cv::Mat image = cv::imread(PATH_FULL_PUZZLE, IMREAD_GRAYSCALE); Mat image = imread(PATH_FULL_PUZZLE, IMREAD_GRAYSCALE);
if (!image.data) { if (!image.data) {
cerr << "Problem loading image of complete puzzle!" << endl; cerr << "Problem loading image of complete puzzle!" << endl;
return false; return false;
} }
//cout << "PRE: " << image.cols << " x " << image.rows << endl; //cout << "PRE: " << image.cols << " x " << image.rows << endl;
cv::resize(image, image, Size(int(ceil(double(image.cols)/mySize.col)*mySize.col), int(ceil(double(image.rows)/mySize.row)*mySize.row))); resize(image, image, Size(int(ceil(double(image.cols)/mySize.col)*mySize.col), int(ceil(double(image.rows)/mySize.row)*mySize.row)));
//cout << "POST: " << image.cols << " x " << image.rows << endl; //cout << "POST: " << image.cols << " x " << image.rows << endl;
// PARAMETERS (for description see top of file) // PARAMETERS (for description see top of file)
int maxCorners = 10000; int maxCorners = 10000;
double qualityLevel = 0.01; double qualityLevel = 0.01;
double minDistance = .5; double minDistance = .5;
cv::Mat mask; Mat mask;
int blockSize = 3; int blockSize = 3;
bool useHarrisDetector = false; bool useHarrisDetector = false;
double k = 0.04; double k = 0.04;
// Detect features - this is where the magic happens // Detect features - this is where the magic happens
cv::goodFeaturesToTrack( image, corners, maxCorners, qualityLevel, minDistance, mask, blockSize, useHarrisDetector, k ); goodFeaturesToTrack( image, corners, maxCorners, qualityLevel, minDistance, mask, blockSize, useHarrisDetector, k );
// Empty the matrix // Empty the matrix
for( int j = 0; j < mySize.row ; j++ ) for( int j = 0; j < mySize.row ; j++ )
@ -138,7 +141,7 @@ bool AbstractionLayer_SURFFeatures::PreProcessingPieces(coor mySize, const vecto
int maxCorners = 500; int maxCorners = 500;
double qualityLevel = 0.05; double qualityLevel = 0.05;
double minDistance = .5; double minDistance = .5;
cv::Mat mask; Mat mask;
int blockSize = 3; int blockSize = 3;
bool useHarrisDetector = false; bool useHarrisDetector = false;
double k = 0.04; double k = 0.04;
@ -148,13 +151,13 @@ bool AbstractionLayer_SURFFeatures::PreProcessingPieces(coor mySize, const vecto
char name[100]; char name[100];
for (unsigned imgID = 0; imgID < mySize.col*mySize.row; imgID++) { for (unsigned imgID = 0; imgID < mySize.col*mySize.row; imgID++) {
sprintf(name, PATH, imgID); sprintf(name, PATH1, imgID);
Mat src = cv::imread(name, IMREAD_GRAYSCALE); Mat src = imread(name, IMREAD_GRAYSCALE);
if (!src.data) { if (!src.data) {
cerr << "Problem loading image of puzzle piece!" << endl; cerr << "Problem loading image of puzzle piece!" << endl;
return false; return false;
} else { } else {
cv::goodFeaturesToTrack(src, corners, maxCorners, qualityLevel, minDistance, mask, blockSize, goodFeaturesToTrack(src, corners, maxCorners, qualityLevel, minDistance, mask, blockSize,
useHarrisDetector, k); useHarrisDetector, k);
if (corners.size() < minFeatures) minFeatures = corners.size(); if (corners.size() < minFeatures) minFeatures = corners.size();
if (corners.size() > maxFeatures) maxFeatures = corners.size(); if (corners.size() > maxFeatures) maxFeatures = corners.size();
@ -173,8 +176,8 @@ bool AbstractionLayer_SURFFeatures::PreProcessingPieces(coor mySize, const vecto
for( unsigned i = 0; i < mySize.col*mySize.row; i++ ) for( unsigned i = 0; i < mySize.col*mySize.row; i++ )
{ {
partArray->at(i)->m_a4.m_numberOfFeaturesDetected = (partArray->at(i)->m_a4.m_numberOfFeaturesDetected - minFeatures) / (maxFeatures - minFeatures); partArray->at(i)->m_a4.m_numberOfFeaturesDetected = (partArray->at(i)->m_a4.m_numberOfFeaturesDetected - minFeatures) / (maxFeatures - minFeatures);
cout << fixed << partArray->at(i)->m_a4.m_numberOfFeaturesDetected << endl; //cout << fixed << partArray->at(i)->m_a4.m_numberOfFeaturesDetected << endl;
} }
cout << endl; //cout << endl;
return true; return true;
} }

View File

@ -12,11 +12,11 @@
#endif #endif
#ifdef _WIN32 //TODO: Code duplicate from AbstractionLayer_1.h #ifdef _WIN32 //TODO: Code duplicate from AbstractionLayer_1.h
#define PATH "..\\..\\..\\pieces\\%04d.jpg" #define PATH1 "..\\..\\..\\pieces\\%04d.jpg"
#elif defined __unix__ #elif defined __unix__
#define PATH "..//..//..//pieces//%04d.jpg" #define PATH1 "..//..//..//pieces//%04d.jpg"
#elif defined __APPLE__ #elif defined __APPLE__
#define PATH "..//..//..//pieces//%04d.jpg" #define PATH1 "..//..//..//pieces//%04d.jpg"
#endif #endif

View File

@ -84,7 +84,7 @@ void solve(vector<LogEntry>& log,Puzzle& puzzleMat)
puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector);
break; break;
case 4://SURFFeature case 4://SURFFeature
puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); puzzleMat.a4.EvaluateQuality(log.back().myCoor,log.back().PieceCollector);
break; break;
case -1://random case -1://random
cout << endl; cout << endl;

View File

@ -44,9 +44,9 @@ public:
bool PreProcessing() bool PreProcessing()
{ {
createBox(); createp_box(); createBox(); createp_box();
/*if(!dp.PreProcessing({cols,rows}, nullptr)) return false; if(!dp.PreProcessing({cols,rows}, nullptr)) return false;
if(!a1.PreProcessing({cols,rows}, &p_myBox)) return false; if(!a1.PreProcessing({cols,rows}, &p_myBox)) return false;
if(!a3.PreProcessing({cols,rows}, &p_myBox)) return false;*/ if(!a3.PreProcessing({cols,rows}, &p_myBox)) return false;
if(!a4.PreProcessing({cols,rows}, &p_myBox)) return false; if(!a4.PreProcessing({cols,rows}, &p_myBox)) return false;
return true; return true;