Image shuffle not working
I know for a fact that the image I receive in the arguments method is correct, because if I omit the shuffle I get the image displayed correctly.
When I use this function the resulting image is exactly the same, as if nothing had been done. I'm not sure if I am handling the ROI copies correctly :
void OpenCvHandler::shuffleImage(cv::Mat &image)
{
int topX = 0, topY = 0, randX = 0, randY = 0;
std::vector<Pair> pile;
while(pile.size() < (PUZZLE_TILE_NUMBER * PUZZLE_TILE_NUMBER))
{
do
{
randX = PUZZLE_MASK_DIMS;
randY = PUZZLE_MASK_DIMS;
randX *= rand() % PUZZLE_TILE_NUMBER;
randY *= rand() % PUZZLE_TILE_NUMBER;
}
while( pairWithinVector(pile, randX, randY) );
cv::Mat src = image(cv::Rect(topX, topY, PUZZLE_MASK_DIMS, PUZZLE_MASK_DIMS));
cv::Mat dst = image(cv::Rect(randX, randY, PUZZLE_MASK_DIMS, PUZZLE_MASK_DIMS));
cv::Mat tmp;
dst.copyTo(tmp);
dst = src;
src = tmp;
pile.push_back(Pair(randX, randY));
topX += PUZZLE_MASK_DIMS;
if(topX == PUZZLE_DIMS)
{
topY += PUZZLE_MASK_DIMS;
topX = 0;
}
}
}
Here are the values of the constants I use :
static const int PUZZLE_TILE_NUMBER = 3;
static const int PUZZLE_MASK_DIMS = 260;
static const int PUZZLE_DIMS = PUZZLE_TILE_NUMBER * PUZZLE_MASK_DIMS;
Essentially with these values I copy tiles of 260x260 in different parts of the image and copy the destination image to where the copied image once was.