2017-12-06 16:25:13 +01:00
|
|
|
#include "../../header.h"
|
2017-11-18 08:16:05 +01:00
|
|
|
|
2017-12-20 18:23:39 +01:00
|
|
|
//use this in second abstraction layer maybe ey?
|
|
|
|
void createRandomAbstraction2()
|
2017-12-06 16:25:13 +01:00
|
|
|
{
|
|
|
|
//get a picture
|
|
|
|
cv::Mat PuzzlePicture = cv::imread("../../Codicil/Images/Balloons.jpg");
|
|
|
|
if(! PuzzlePicture.data )
|
|
|
|
{
|
|
|
|
cout << "Could not open or find the image" << std::endl ;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//split a picture into mxn pieces
|
|
|
|
cv::Size smallSize ((int)(PuzzlePicture.cols/getCols()) ,(int)(PuzzlePicture.rows/getRows()));
|
|
|
|
// get the image data
|
|
|
|
|
|
|
|
vector<cv::Mat> smallChannels;
|
|
|
|
unsigned int i=0,j=0;
|
|
|
|
for ( int y=0; y<=PuzzlePicture.rows-smallSize.height; y += smallSize.height )
|
|
|
|
{
|
|
|
|
|
|
|
|
for ( int x=0 ; x<=PuzzlePicture.cols-smallSize.width; x += smallSize.width )
|
|
|
|
{
|
|
|
|
//split into different ROIs
|
|
|
|
cv::Rect rect = cv::Rect (x ,y , smallSize.width, smallSize.height );
|
|
|
|
cv::Mat tmpSmallPicture = cv::Mat(PuzzlePicture,rect);
|
|
|
|
cv::split(tmpSmallPicture, smallChannels);
|
|
|
|
|
|
|
|
//save color into individual PuzzlePieces in Matrix
|
|
|
|
PuzzlePiece tmpPiece = getPiece(j,i);
|
|
|
|
tmpPiece.r = cv::mean(smallChannels[0]).operator[](0);
|
|
|
|
tmpPiece.g = cv::mean(smallChannels[1]).operator[](0);
|
|
|
|
tmpPiece.b = cv::mean(smallChannels[2]).operator[](0);
|
2017-12-07 16:26:45 +01:00
|
|
|
setPiece(coor(j,i),tmpPiece);
|
2017-12-06 16:25:13 +01:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-18 08:16:05 +01:00
|
|
|
//shuffles around a box, randomizing pieces and orientation
|
2017-12-20 18:23:39 +01:00
|
|
|
vector<Part> randomBox::shuffle()
|
2017-11-18 08:16:05 +01:00
|
|
|
{
|
|
|
|
random_shuffle(Box.begin(),Box.end());
|
2017-12-13 10:47:15 +01:00
|
|
|
for (auto &i:Box)
|
2017-12-06 16:25:13 +01:00
|
|
|
{
|
2017-12-13 10:47:15 +01:00
|
|
|
i.shift(rand()%4);
|
|
|
|
i.resetShift();
|
2017-12-06 16:25:13 +01:00
|
|
|
}
|
|
|
|
|
2017-11-18 08:16:05 +01:00
|
|
|
numerateBox(Box);
|
|
|
|
return Box;
|
|
|
|
}
|