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 pitch black. I'm not sure if I am handling the ROI copies correctly :
void OpenCvHandler::shuffleImage(cv::Mat &image)
{
int randX = PUZZLE_MASK_DIMS;
int randY = PUZZLE_MASK_DIMS;
int topX = 0, topY = 0;
std::vector<Pair> pile;
while(pile.size() < (PUZZLE_TILE_NUMBER * PUZZLE_TILE_NUMBER))
{
do
{
randX *= rand() % PUZZLE_TILE_NUMBER;
randY *= rand() % PUZZLE_TILE_NUMBER;
}
while( pairWithinVector(pile, randX, randY) );
cv::Mat src = image(cv::Rect(topX, topY, image.size().width, image.size().height));
cv::Mat dst = image(cv::Rect(randX, randY, image.size().width, image.size().height));
cv::Mat tmp = dst;
src.copyTo(dst);
tmp.copyTo(src);
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;