int i = 768;
int j = 1024;
int startRow = 0;
int endRow = 49;
int startCol = 0;
int endCol = 36;
Matrix SceneMatrix(i, j, input_data); //Matrix of cluttered_scene
Matrix WallyMatrix(49, 36, wally_data); //Matrix of wally
Matrix BestMatrix = SceneMatrix.getBlock(startRow, endRow, startCol, endCol); //Matrix to contain the best result that matches wally, based on a subset of SceneMatrix
Matrix BestMatrix2 = BestMatrix; //Set to same details as BestMatrix(Copy constructer runs here)
Matrix BestMatrix3 = BestMatrix; //Set to same details as BestMatrix(Copy constructer runs here)
if (ans == 1) { //If SSD
BestMatrix.setScore(SumOfSquaredDifferences(WallyMatrix, BestMatrix));
BestMatrix2.setScore(SumOfSquaredDifferences(WallyMatrix, BestMatrix2));
BestMatrix3.setScore(SumOfSquaredDifferences(WallyMatrix, BestMatrix3));
}
int corrStartRow = 0; //Pos of best option
int corrEndRow = 0;
int corrStartCol = 0;
int corrEndCol = 0;
int corrStartRow2 = 0; //Pos of second best option
int corrEndRow2 = 0;
int corrStartCol2 = 0;
int corrEndCol2 = 0;
int corrStartRow3 = 0; //Pos of third best option
int corrEndRow3 = 0;
int corrStartCol3 = 0;
int corrEndCol3 = 0;
double moveValue = 6; //Amount that the scanner will shift each iteration
for (endRow; endRow < (i - 49); endRow += moveValue, startRow+= moveValue) { //Loop through each row
for (endCol; endCol < (j - 36); endCol += moveValue, startCol += moveValue) { //Loop through each column
Matrix TestMatrix = SceneMatrix.getBlock(startRow, endRow, startCol, endCol); //Matrix that will be tested against current best matrix
if (ans == 1) { //If SSD
TestMatrix.setScore(SumOfSquaredDifferences(WallyMatrix, TestMatrix)); //Test score using SSD
}
if (ans == 1) { //If SSD
if (TestMatrix.getScore() < BestMatrix.getScore()) { //Best option
BestMatrix = TestMatrix; //Set BestMatrix and a set of coords to the test matrix, as this is better than the previous BestMatrix
corrStartRow = startRow; //Coords to be used when drawing rectangle
corrEndRow = endRow;
corrStartCol = startCol;
corrEndCol = endCol;
}
} //end if ans == 1 (SSD)
} //End for loop of columns
endCol = 36; //Move to next row
startCol = 0;
} //End for loop of rows
int i = 768;
int j = 1024;
int startRow = 0;
int endRow = 49;
int startCol = 0;
int endCol = 36;
Matrix SceneMatrix(i, j, input_data); //Matrix of cluttered_scene
Matrix WallyMatrix(49, 36, wally_data); //Matrix of wally
Matrix BestMatrix = SceneMatrix.getBlock(startRow, endRow, startCol, endCol); //Matrix to contain the best result that matches wally, based on a subset of SceneMatrix
Matrix BestMatrix2 = BestMatrix; //Set to same details as BestMatrix(Copy constructer runs here)
Matrix BestMatrix3 = BestMatrix; //Set to same details as BestMatrix(Copy constructer runs here)
if (ans == 1) { //If SSD
BestMatrix.setScore(SumOfSquaredDifferences(WallyMatrix, BestMatrix));
BestMatrix2.setScore(SumOfSquaredDifferences(WallyMatrix, BestMatrix2));
BestMatrix3.setScore(SumOfSquaredDifferences(WallyMatrix, BestMatrix3));
}
int corrStartRow = 0; //Pos of best option
int corrEndRow = 0;
int corrStartCol = 0;
int corrEndCol = 0;
int corrStartRow2 = 0; //Pos of second best option
int corrEndRow2 = 0;
int corrStartCol2 = 0;
int corrEndCol2 = 0;
int corrStartRow3 = 0; //Pos of third best option
int corrEndRow3 = 0;
int corrStartCol3 = 0;
int corrEndCol3 = 0;
double moveValue = 6; //Amount that the scanner will shift each iteration
for (endRow; endRow < (i - 49); endRow += moveValue, startRow+= moveValue) { //Loop through each row
for (endCol; endCol < (j - 36); endCol += moveValue, startCol += moveValue) { //Loop through each column
Matrix TestMatrix = SceneMatrix.getBlock(startRow, endRow, startCol, endCol); //Matrix that will be tested against current best matrix
if (ans == 1) { //If SSD
TestMatrix.setScore(SumOfSquaredDifferences(WallyMatrix, TestMatrix)); //Test score using SSD
}
if (ans == 1) { //If SSD
if (TestMatrix.getScore() < BestMatrix.getScore()) { //Best option
BestMatrix = TestMatrix; //Set BestMatrix and a set of coords to the test matrix, as this is better than the previous BestMatrix
corrStartRow = startRow; //Coords to be used when drawing rectangle
corrEndRow = endRow;
corrStartCol = startCol;
corrEndCol = endCol;
}
} //end if ans == 1 (SSD)
} //End for loop of columns
endCol = 36; //Move to next row
startCol = 0;
} //End for loop of rows
To copy to clipboard, switch view to plain text mode
#pragma once
class Matrix { //This matrix class allows me to make a new object for each matrix I need
public: //Allows anything that is public to be accessed (e.g. matrix1.getBlock)
Matrix(int sizeR, int sizeC, double input_data[]); //Class constructer
~Matrix(); //Class Destructer
Matrix getBlock(int startRow, int endRow, int startCol, int endCol); //Function which takes a limit in terms of columns and rows, and returns the Matrix inside it
double* Matrix::getMatrixVals(); //Function which returns the data array in a matrix
double getScore(); //Function which returns the score variable (as it is private and cannot otherwise be accessed outside of the scope of the Matrix class)
void setScore(double Score); //Function which sets the score variable
int* getSceneVals(); //Function which returns the indexes that the new matrix occupied in its larger matrix (where the 36 x 49 matrix existed in terms of position inside the 1024 x 768 matrix)
Matrix(const Matrix& e); //Copy Constructer
private: //Can't be accessed outside of Matrix class
int M, N; //Amount of rows and columns in the matrix
double *data; //The data read into the matrix
double *newData; //The new set of data, taken out of the data variable, based on the getBlock function
double score; //The score, assigned by either the Sum of Squared Differences function, or the Normalized Correlation function
int* posInScene; //An array which contains the indexes that the new matrix occupied in its larger matrix (where the 36 x 49 matrix existed in terms of position inside the 1024 x 768 matrix)
//To be used for putting a square around wally
};
Matrix::Matrix(int sizeR, int sizeC, double input_data[]) { //The Class Constructer (runs whenever a new Matrix object is created)
M = sizeR; //M = height
N = sizeC; //N = width
data = new double[M*N]; //Sets the total space of the data array
newData = new double[36*49]; //Sets the total space of the new data array
posInScene = new int[36*49]; //Sets the total space of the position in scene array
for (int ii = 0; ii < M*N; ii++) { //Loops through the rows * columns of the matrix, to add the data read into the function to the data function
data[ii] = input_data[ii]; //Adding each value in the data array, one by one
}
}
Matrix::~Matrix() { //The class destructer, which runs every time a matrix is deleted (included when it is passed through a function as a reference)
} //End of class destructer
Matrix Matrix::getBlock(int startRow, int endRow, int startCol, int endCol) { //Function which returns a Matrix based on a start/end row/column
int currentCol = startCol;
int currentRow = startRow; //Temporary variables used to retain value of start row/start column
int counter = 0;
for (currentRow; currentRow < endRow; currentRow++) {
for (currentCol; currentCol < endCol; currentCol++) { //The nested for loop means this will run endCol * endRow times (in this case, 36 * 49 times)
newData[counter] = data[(currentRow * N) + currentCol]; //This formula will set each value of new data as the value of the matrix, as if it were a 2d matrix, using the formula (currentRow * N) + currentCol, using the values passed through the function
posInScene[counter] = (currentRow * N) + currentCol; //This will store the position that each value of newData had inside data, for future reference, like when identifying wally in the cluttered_scene image
counter++; //Incrementing the counter
} //End of the currentCol for loop
currentCol = startCol; //After finishing a row, this moves onto the next one
} //End of the currentRow for loop
Matrix NewMatrix(endRow - startRow, endCol - startCol, newData); //The matrix that will be returned as the subset of the original matrix
return NewMatrix;
} //End getBlock function
Matrix::Matrix(const Matrix& e) { //Copy Constructer
M = e.M;
N = e.N;
data = e.data;
newData = e.newData;
score = e.score;
posInScene = e.posInScene; ///Whenever a Matrix is copied, each of these variables is set to what it was
} //End copy constructer
double* Matrix::getMatrixVals() { //Function which returns the values in the data array
double* matrixVals; //Declaring the array
int size = M * N;
matrixVals = new double[size]; ///Declares the size of the array
for (int i = 0; i < size; i++) { //Loops through as many values as there are in the matrix
matrixVals[i] = data[i]; //Replacing every value of the array as it goes
}
return matrixVals; //Returning a double array
} //End of the getmatrixvals function
#pragma once
class Matrix { //This matrix class allows me to make a new object for each matrix I need
public: //Allows anything that is public to be accessed (e.g. matrix1.getBlock)
Matrix(int sizeR, int sizeC, double input_data[]); //Class constructer
~Matrix(); //Class Destructer
Matrix getBlock(int startRow, int endRow, int startCol, int endCol); //Function which takes a limit in terms of columns and rows, and returns the Matrix inside it
double* Matrix::getMatrixVals(); //Function which returns the data array in a matrix
double getScore(); //Function which returns the score variable (as it is private and cannot otherwise be accessed outside of the scope of the Matrix class)
void setScore(double Score); //Function which sets the score variable
int* getSceneVals(); //Function which returns the indexes that the new matrix occupied in its larger matrix (where the 36 x 49 matrix existed in terms of position inside the 1024 x 768 matrix)
Matrix(const Matrix& e); //Copy Constructer
private: //Can't be accessed outside of Matrix class
int M, N; //Amount of rows and columns in the matrix
double *data; //The data read into the matrix
double *newData; //The new set of data, taken out of the data variable, based on the getBlock function
double score; //The score, assigned by either the Sum of Squared Differences function, or the Normalized Correlation function
int* posInScene; //An array which contains the indexes that the new matrix occupied in its larger matrix (where the 36 x 49 matrix existed in terms of position inside the 1024 x 768 matrix)
//To be used for putting a square around wally
};
Matrix::Matrix(int sizeR, int sizeC, double input_data[]) { //The Class Constructer (runs whenever a new Matrix object is created)
M = sizeR; //M = height
N = sizeC; //N = width
data = new double[M*N]; //Sets the total space of the data array
newData = new double[36*49]; //Sets the total space of the new data array
posInScene = new int[36*49]; //Sets the total space of the position in scene array
for (int ii = 0; ii < M*N; ii++) { //Loops through the rows * columns of the matrix, to add the data read into the function to the data function
data[ii] = input_data[ii]; //Adding each value in the data array, one by one
}
}
Matrix::~Matrix() { //The class destructer, which runs every time a matrix is deleted (included when it is passed through a function as a reference)
} //End of class destructer
Matrix Matrix::getBlock(int startRow, int endRow, int startCol, int endCol) { //Function which returns a Matrix based on a start/end row/column
int currentCol = startCol;
int currentRow = startRow; //Temporary variables used to retain value of start row/start column
int counter = 0;
for (currentRow; currentRow < endRow; currentRow++) {
for (currentCol; currentCol < endCol; currentCol++) { //The nested for loop means this will run endCol * endRow times (in this case, 36 * 49 times)
newData[counter] = data[(currentRow * N) + currentCol]; //This formula will set each value of new data as the value of the matrix, as if it were a 2d matrix, using the formula (currentRow * N) + currentCol, using the values passed through the function
posInScene[counter] = (currentRow * N) + currentCol; //This will store the position that each value of newData had inside data, for future reference, like when identifying wally in the cluttered_scene image
counter++; //Incrementing the counter
} //End of the currentCol for loop
currentCol = startCol; //After finishing a row, this moves onto the next one
} //End of the currentRow for loop
Matrix NewMatrix(endRow - startRow, endCol - startCol, newData); //The matrix that will be returned as the subset of the original matrix
return NewMatrix;
} //End getBlock function
Matrix::Matrix(const Matrix& e) { //Copy Constructer
M = e.M;
N = e.N;
data = e.data;
newData = e.newData;
score = e.score;
posInScene = e.posInScene; ///Whenever a Matrix is copied, each of these variables is set to what it was
} //End copy constructer
double* Matrix::getMatrixVals() { //Function which returns the values in the data array
double* matrixVals; //Declaring the array
int size = M * N;
matrixVals = new double[size]; ///Declares the size of the array
for (int i = 0; i < size; i++) { //Loops through as many values as there are in the matrix
matrixVals[i] = data[i]; //Replacing every value of the array as it goes
}
return matrixVals; //Returning a double array
} //End of the getmatrixvals function
To copy to clipboard, switch view to plain text mode
Bookmarks