Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 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;

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 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);
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;
click to hide/show revision 3
Fixed some logic errors

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 pitch black. 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 randX = PUZZLE_MASK_DIMS;
int randY = PUZZLE_MASK_DIMS;
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, image.size().width, image.size().height));
PUZZLE_MASK_DIMS, PUZZLE_MASK_DIMS));
    cv::Mat dst = image(cv::Rect(randX, randY, image.size().width, image.size().height));
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.