in my project I'm using OpenCL with Lode's QuickCG (documentation here).
We are having a problemam that, we want to identify when a pixel matches a green chroma key color and then draw the second image instead (background).
Here's the kernel code:
__kernel void convolute(__global float* inputImage1, __global float* inputImage2, __global float* outputImage, __global float* filter, int width, int height ,float bias, float factor)
{
int x = get_global_id(0);
int y = get_global_id(1);
float sumR = 0;
float sumG = 0;
float sumB = 0;
float cR = 40.0;
float cG = 250.0;
float cB = 20.0;
float tolerance = 100.0;
if ( (x >= 0) &&
(x < width) &&
(y >= 0) &&
(y < height)) {
float pR = inputImage1[x * 3 + y * width * 3 + 0];
float pG = inputImage1[x * 3 + y * width * 3 + 1];
float pB = inputImage1[x * 3 + y * width * 3 + 2];
float d = (sqrt(pow((cR - pR), 2) + pow((cG - pG), 2) + pow((cB - pB), 2)));
if (d <= tolerance) {
sumR += inputImage2[x * 3 + y * width * 3 + 0];
sumG += inputImage2[x * 3 + y * width * 3 + 1];
sumB += inputImage2[x * 3 + y * width * 3 + 2];
}
else {
sumR += pR;
sumG += pG;
sumB += pB;
}
}
outputImage[y * width * 3 + x * 3] = min_max(sumR);
outputImage[y * width * 3 + x * 3 + 1] = min_max(sumG);
outputImage[y * width * 3 + x * 3 + 2] = min_max(sumB);
}
We tried in two ways, first is verifying just the green color (just for a test) and using this formula that my professor gave
Both ways we could not succeed, I believe that the probleam is that the values inside the kernel code are to low, so the green is not going to be 255, actualy with a if statement, we verified that is something around 1e-46
Is there a method that can convert this to a compreensible integer or something that we can work with?