I am having some trouble with an OpenGL code. The input is correct, but the output is not.
The code is as follows. When I change num_tiles_per_dimension to 1 then everything works well, which goes to show that the code is pretty much working. The full code is at: https://github.com/sjhalayka/light_blocking_asymmetric
int num_tiles_per_dimension = 2;
std::vector<cv::Mat> array_of_input_mats = splitImage(input_mat, num_tiles_per_dimension, num_tiles_per_dimension);
std::vector<cv::Mat> array_of_output_mats;
for (size_t i = 0; i < array_of_input_mats.size(); i++)
{
string s = "_input_" + to_string(i) + ".png";
imwrite(s.c_str(), array_of_input_mats[i]);
vector<float> output_pixels(4 * array_of_input_mats[i].rows * array_of_input_mats[i].cols);
gpu_compute(
compute_shader_program,
&output_pixels[0],
array_of_input_mats[i],
input_light_mat_with_dynamic_lights,
input_light_blocking_mat);
Mat uc_output_small(array_of_input_mats[i].rows, array_of_input_mats[i].cols, CV_8UC4);
for (size_t x = 0; x < (4 * uc_output_small.rows * uc_output_small.cols); x += 4)
{
uc_output_small.data[x + 0] = static_cast<unsigned char>(output_pixels[x + 0] * 255.0);
uc_output_small.data[x + 1] = static_cast<unsigned char>(output_pixels[x + 1] * 255.0);
uc_output_small.data[x + 2] = static_cast<unsigned char>(output_pixels[x + 2] * 255.0);
uc_output_small.data[x + 3] = 255;
}
array_of_output_mats.push_back(uc_output_small);
// These images show that something's not working right where num_tiles_per_dimension is >= 2
// there are duplicate output images
s = "_output_" + to_string(i) + ".png";
imwrite(s.c_str(), array_of_output_mats[i]);
}
cv::Mat uc_output = imageCollage(array_of_output_mats, num_tiles_per_dimension, num_tiles_per_dimension);
The input images are:
The output images are:
As you can see, the output is not right, even though the input is right – the 1st and 2nd output images are repeats. This should not be.
Any ideas?
I used the tile splitImage and imageCollage functions in another part of the program (the randomization of the hue and brightness), and it works just fine too.
In any case, here is the output where num_tiles_per_dimension = 2: