the problem is that both the opencv and the effect code snippets are meant to work on texture coordinates and from the perspective of the output image.
you can imagine a loop going over all output pixels, row by row, pixel by pixel.
the opencv undistort code (and its effect copycat) get the following job done:
- we have the destination texel already
- what texel of the source image should be displayed here?
so we have a function like:
sourceTexCd = undistort( destinationTexCd )
outputcolor = sample source image at sourceTexCd
now when we want to take arbitrary positions (not fixed to a known output grid) we need the opposite of that function.
- we have the source position within the source image.
- we need to know the destination position.
so we need something like:
sourceTexCd = asTexCd( sourcePos )
destinationTexCd = inverse_undistort( sourceTexCd )
destinationPos = fromTexCd( destinationTexCd )
the problem will then be to write that inverse_undistort function. maybe we need a math program for that. get the formula in and solve for “p”.
for now we maybe should check if the original behaviour of the opencv / effect could be patched somehow with the new plugin (and get the same result).
therefore i used a pipet which samples the original texture. (so we again need to undistort destination texcoords to get source texcoords; and sample the color in the source image - like in the original code)
i found some small error in the plugin code, changed it and checked that in again, but somehow didn’t get the dll running. so if someone could compile it. pleeeaase?
in the following patch the middle iobox color should look like the renderer on the left. (with a freshly compiled undistort plugin)
can somebody aprove that?
testDistort.v4p (23.3 kB)