Processing of complete image added
Actually not running - never did since Max did stuff :)
This commit is contained in:
		@@ -1,15 +1,94 @@
 | 
			
		||||
#include "AbstractionLayer_SURFFeatures.h"
 | 
			
		||||
 | 
			
		||||
// Parameters for algorithm:
 | 
			
		||||
// maxCorners – The maximum number of corners to return. If there are more corners than that will be found, the strongest of them will be returned
 | 
			
		||||
// qualityLevel – Characterizes the minimal accepted quality of image corners;
 | 
			
		||||
// minDistance – The minimum possible Euclidean distance between the returned corners
 | 
			
		||||
// mask – The optional region of interest. It will specify the region in which the corners are detected
 | 
			
		||||
// blockSize – Size of the averaging block for computing derivative covariation
 | 
			
		||||
// useHarrisDetector – Indicates, whether to use operator or cornerMinEigenVal()
 | 
			
		||||
// k – Free parameter of Harris detector
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include "opencv2/highgui.hpp"
 | 
			
		||||
#include "opencv2/imgproc.hpp"
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#define PATH_FULL_PUZZLE "..\\..\\..\\puzzle_img\\puzzle1.jpg"
 | 
			
		||||
#elif defined __unix__
 | 
			
		||||
#define PATH_FULL_PUZZLE "..//..//..//puzzle_img//puzzle1.jpg"
 | 
			
		||||
#elif defined __APPLE__
 | 
			
		||||
    #define PATH_FULL_PUZZLE "..//..//..//puzzle_img//puzzle1.jpg"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
using namespace cv;
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
bool AbstractionLayer_SURFFeatures::PreProcessing(coor mySize, const vector<Part*>* partArray)
 | 
			
		||||
{
 | 
			
		||||
    InitialiseConstraintMatrixSize(mySize.col, mySize.row);
 | 
			
		||||
    std::vector< cv::Point2f > corners;                         // Variable to store corner-positions at
 | 
			
		||||
 | 
			
		||||
    //TODO: Gesamtbild mit OpenCV einlesen
 | 
			
		||||
    //TODO: Gesamtbild anhand der berechneten Spalten und Zeilen auseinander schneiden (Sind in der puzzleKlasse gespeichert)
 | 
			
		||||
    //TODO: Features der einzelnen Felder des ausgeschnittenen Gesamtbildes in der m_constraintMatrix speichern
 | 
			
		||||
    // -- Complete puzzle image processing --
 | 
			
		||||
    // 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);
 | 
			
		||||
    //cout << "PRE:  " << image.cols << " x " << image.rows << endl;
 | 
			
		||||
    cv::resize(image, image, Size(int(ceil(double(image.cols)/mySize.col)*mySize.row), int(ceil(double(image.rows)/mySize.row)*mySize.row)));
 | 
			
		||||
    //cout << "POST: " << image.cols << " x " << image.rows << endl;
 | 
			
		||||
 | 
			
		||||
    // Speichert die Features der linken oberen Ecke des Gesamtpuzzles in die constraintMatrix
 | 
			
		||||
    m_constraintMatrix[0][0].m_numberOfFeaturesDetected = 50;
 | 
			
		||||
    // PARAMETERS (for description see top of file)
 | 
			
		||||
    int maxCorners = 10000;
 | 
			
		||||
    double qualityLevel = 0.01;
 | 
			
		||||
    double minDistance = .5;
 | 
			
		||||
    cv::Mat mask;
 | 
			
		||||
    int blockSize = 3;
 | 
			
		||||
    bool useHarrisDetector = false;
 | 
			
		||||
    double k = 0.04;
 | 
			
		||||
 | 
			
		||||
    // Detect features - this is where the magic happens
 | 
			
		||||
    cv::goodFeaturesToTrack( image, corners, maxCorners, qualityLevel, minDistance, mask, blockSize, useHarrisDetector, k );
 | 
			
		||||
 | 
			
		||||
    int pieceColSize = image.cols/mySize.col;
 | 
			
		||||
    int pieceRowSize = image.rows/mySize.row;
 | 
			
		||||
    // Calculate number of features for each piece-position
 | 
			
		||||
    for( int i = 0; i < corners.size(); i++ )   // For all found features
 | 
			
		||||
    {
 | 
			
		||||
        // Increment number of found pieces
 | 
			
		||||
        m_constraintMatrix[int(ceil(corners[i].x/pieceColSize))-1][int(ceil(corners[i].y/pieceRowSize))-1].m_numberOfFeaturesDetected++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Get minimal and maximal number of features -> TODO: Do in first loop to safe time?
 | 
			
		||||
    int minFeatures = int(m_constraintMatrix[0][0].m_numberOfFeaturesDetected);
 | 
			
		||||
    int maxFeatures = int(m_constraintMatrix[0][0].m_numberOfFeaturesDetected);
 | 
			
		||||
    for( int j = 0; j < mySize.row ; j++ )
 | 
			
		||||
    {
 | 
			
		||||
        for( int i = 0; i < mySize.col; i++ )
 | 
			
		||||
        {
 | 
			
		||||
            if(m_constraintMatrix[i][j].m_numberOfFeaturesDetected < minFeatures) minFeatures = int(m_constraintMatrix[i][j].m_numberOfFeaturesDetected);
 | 
			
		||||
            if(m_constraintMatrix[i][j].m_numberOfFeaturesDetected > maxFeatures) maxFeatures = int(m_constraintMatrix[i][j].m_numberOfFeaturesDetected);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Calculate percentage from 0 to 100% with numberOfFeatures and safe it
 | 
			
		||||
    for( int j = 0; j < mySize.row ; j++ )
 | 
			
		||||
    {
 | 
			
		||||
        for( int i = 0; i < mySize.col; i++ )
 | 
			
		||||
        {
 | 
			
		||||
            m_constraintMatrix[i][j].m_numberOfFeaturesDetected = (m_constraintMatrix[i][j].m_numberOfFeaturesDetected - minFeatures) / (maxFeatures - minFeatures);
 | 
			
		||||
            //cout << fixed << m_constraintMatrix[i][j].m_numberOfFeaturesDetected << " ";
 | 
			
		||||
        }
 | 
			
		||||
        //cout << endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // DEBUG - Display image
 | 
			
		||||
    /*for( size_t i = 0; i < corners.size(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
        cv::circle( image, corners[i], 2, cv::Scalar( 255. ), -1 );
 | 
			
		||||
    }
 | 
			
		||||
    cv::namedWindow( "Output", CV_WINDOW_AUTOSIZE );
 | 
			
		||||
    cv::imshow( "Output", image );
 | 
			
		||||
 | 
			
		||||
    cv::waitKey(0);*/
 | 
			
		||||
 | 
			
		||||
    //TODO: Alle Bilder mit OpenCV öffnen und deren erkannten Features in SURFFeature_Properties der Part-Klasse speichern
 | 
			
		||||
    // Speichert die erkannten Features des jeweiligen Bilds im partArray an der Stelle (->at(xxx))
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ public:
 | 
			
		||||
    AbstractionLayer_SURFFeatures_Properties() {}
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    uint16_t m_numberOfFeaturesDetected;
 | 
			
		||||
    float m_numberOfFeaturesDetected;
 | 
			
		||||
    friend class AbstractionLayer_SURFFeatures;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user