180 degree live fisheye distortion correction

BerryJP

New Member
I have searched for a few hours and can't seem to find anything that can correct the distortion on a live feed.

Does such a feature exist? Are there any workarounds?

I use a z-cam E1 with a Meike 6.5mm lens, connected via HDMI to an Avermedia Gamer HD2.

I would love to be able to fix the distortion for both live streams and recordings via OBS. It seems there are no warp options in OBS at all. Am I being blind, or is it something that cannot be done?
{9B1148C9-20F1-417F-9772-18F277E2C750}.png.jpg
 

MudBocx

New Member
The first thing that I can think of is to use a (physical) lense adapter to reduce distortion and not do it in post (software). That should work if you have the cam in a mostly stationary position.

The other option you could try is using a virtual cam tool with your HDMI input, apply filters to correct distortion and link that virtual cam back to OBS.
 
Last edited:

jlm70

New Member
Ideally... a video filter within OBS might sound quite better/easier (similar to distortion filters within Lightroom).
Using a good Sony mirrorless and optics but... being quite close (due to space restrictions) I'd like eliminating the wide angle distortion happening to the speaker :-)
 

bansheekft

New Member
was looking for the same. reading the initial post and Berrys setup (with the meike 6.5) reminded me of an open fx plugin for davinci resolve that i use for that lens:
https://github.com/roukou3/DCTL witch is capable of exactly that. and it's under MIT license
unfortunately my coding knowledge is close to non existent but i believe someone more advanced could turn it into a obs filter plugin. a shader could be a possibility if i understand that concept correctly... i tried but couldn't even figure out where to start... so don't hold your breath...
seeing it integrated into streamFX would be awesome.
 

Trekaholic

New Member
Solution found (I think)
I had the same issue, and couldn't find a solution. Every search just returned how to make a fisheye effect with a shade filter.
I had an idea that what I was trying to do was the exact opposite, so what if I could reverse what the fisheye filter was doing.
I found this video https://youtu.be/Y8RxMtzr23o and I followed the directions. It did what I expected, it doubled the fisheye effect I was already getting using my Vivitar go pro clone. At first I tried to change the fisheye.shader file using a text editor to do the opposite. As I'm new to OBS I kept trying different things until I noticed the settings for the shader itself.

All I had to do was install the fisheye shader and use the power setting at a negative number. In my case it is -0.11 but play around with it to get it just right for your camera. I hope this helps :D
Albie :D
albie.ws
 

Attachments

  • Unfisheye.png
    Unfisheye.png
    16 KB · Views: 3,476
Last edited:

Dibutil

New Member
Solution found (I think)
...
All I had to do was install the fisheye shader and use the power setting at a negative number. In my case it is -0.11 but play around with it to get it just right for your camera. I hope this helps :D
Albie :D
albie.ws

Excellent method and as simple as expected!
 

5am

New Member
I've been having problems with this one.. All the videos I see are for a windows install. I don't see any .dll or .pdb files where it wants me to install the files. Anybody have any luck installing this on a mac?
 

Suslik V

Active Member
@5am If there is "Sharpness" filter on mac and you don't use it, then you can replace the shader program of the filter (named "sharpness.effect") by this text:
C:
// Based on Sharpness shader of OBS Studio v27.0.0,
// And https://github.com/Oncorporation/obs-shaderfilter/

uniform float4x4 ViewProj;
uniform texture2d image;

uniform float sharpness;
uniform float texture_width;
uniform float texture_height;

sampler_state def_sampler {
    Filter   = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VertData {
    float4 pos : POSITION;
    float2 uv  : TEXCOORD0;
};

VertData VSDefault(VertData v_in)
{
    VertData vert_out;
    vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
    vert_out.uv  = v_in.uv;
    return vert_out;
}

float4 PSDrawBare(VertData v_in) : TARGET
{
    int center_x_percent = 50;
    int center_y_percent = 50;
    float power = -sharpness;
    float2 uv_pixel_interval;
    uv_pixel_interval.x = 1.0 / texture_width;
    uv_pixel_interval.y = 1.0 / texture_height;
    float2 center_pos = float2(center_x_percent * .01, center_y_percent * .01);
    float2 uv = v_in.uv;
    float b;
    if (uv_pixel_interval.x < uv_pixel_interval.y){
        b = center_pos.x;
    } else {
        b = center_pos.y;
    }
    uv = center_pos  + normalize(v_in.uv - center_pos) * atan(distance(center_pos, v_in.uv) * -power * 10.0) * b / atan(-power * b * 10.0);
    return image.Sample(def_sampler, uv);
}

technique Draw
{
    pass
    {
        vertex_shader = VSDefault(v_in);
        pixel_shader  = PSDrawBare(v_in);
    }
}

Now the OBS Studio filter named Sharpness will start to act like "unfish" (the sharpness value now controls the amount of the distortion, 0.18 is OK for the image provided by the topic starter).

And keep copy of the original "sharpness.effect" just in case.
 

Dee_mister

New Member
@5am If there is "Sharpness" filter on mac and you don't use it, then you can replace the shader program of the filter (named "sharpness.effect") by this text:
C:
// Based on Sharpness shader of OBS Studio v27.0.0,
// And https://github.com/Oncorporation/obs-shaderfilter/

uniform float4x4 ViewProj;
uniform texture2d image;

uniform float sharpness;
uniform float texture_width;
uniform float texture_height;

sampler_state def_sampler {
    Filter   = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VertData {
    float4 pos : POSITION;
    float2 uv  : TEXCOORD0;
};

VertData VSDefault(VertData v_in)
{
    VertData vert_out;
    vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
    vert_out.uv  = v_in.uv;
    return vert_out;
}

float4 PSDrawBare(VertData v_in) : TARGET
{
    int center_x_percent = 50;
    int center_y_percent = 50;
    float power = -sharpness;
    float2 uv_pixel_interval;
    uv_pixel_interval.x = 1.0 / texture_width;
    uv_pixel_interval.y = 1.0 / texture_height;
    float2 center_pos = float2(center_x_percent * .01, center_y_percent * .01);
    float2 uv = v_in.uv;
    float b;
    if (uv_pixel_interval.x < uv_pixel_interval.y){
        b = center_pos.x;
    } else {
        b = center_pos.y;
    }
    uv = center_pos  + normalize(v_in.uv - center_pos) * atan(distance(center_pos, v_in.uv) * -power * 10.0) * b / atan(-power * b * 10.0);
    return image.Sample(def_sampler, uv);
}

technique Draw
{
    pass
    {
        vertex_shader = VSDefault(v_in);
        pixel_shader  = PSDrawBare(v_in);
    }
}

Now the OBS Studio filter named Sharpness will start to act like "unfish" (the sharpness value now controls the amount of the distortion, 0.18 is OK for the image provided by the topic starter).

And keep copy of the original "sharpness.effect" just in case.

Hi Suslik,

thank you so much for your efforts, I've registered here to to reply here, I too been having this issue on macOS for a long time, I did as follows, renamed the file sharpness.effect to sharpness.bak and then put the above in place, although sharpen is there to select, there are no options to adjust anything, no bar, nothing. I double check the code maybe I didn't copy correctly but all is is exact.

Then....SUCCESS folks, it really works!!!

Right click on the newly created file sharpness.effect , then select get info, under name & extension you will see a box underneath labelled hide extension make sure it is unticked, then goto file name and you may well see it is actually sharpness.effect.txt , yes remove the txt and thats it, start obs and slider will appear after applying the sharpen filter to the input vid.

Big one to Suslik, nice one!!!!


Dee
 

Suslik V

Active Member
@danielholliger No I don't have.

I only can think of the StreamFX plugin by @Xaymar :
It seems that it has support for the custom shaders on Mac too.
But it is much harder today for me to complete any task, so let's hope someone with good knowledge of the programming can adapt the shader for the StreamFX too.

Note: on Windows there is https://obsproject.com/forum/resources/obs-shaderfilter.775/ that was the source of the fisheye ("unfish") effect. The effect itself was added in recent updates to the plugin.
 

pqtato

New Member
I know this is late but on Linux, I got this to work by installing this plugin and using this shader https://obsproject.com/forum/resources/obs-shaderfilter-plus.929/
To remove fisheye, just make the power negative.
Code:
uniform int center_x_percent = 50;
uniform int center_y_percent = 50;
uniform float power = 1.75;

float4 render(float2 uv2) : TARGET
{
    float2 center_pos = float2(center_x_percent * .01, center_y_percent * .01);
    float2 uv = uv2;
    if (power >= 0.0001){
        float b = sqrt(dot(center_pos, center_pos));
        uv = center_pos  + normalize(uv2 - center_pos) * tan(distance(center_pos, uv2) * power) * b / tan( b * power);
    } else if(power <= -0.0001){
        float b;
        if (uv2.x < uv2.y){
            b = center_pos.x;
        } else {
            b = center_pos.y;
        }
        uv = center_pos  + normalize(uv2 - center_pos) * atan(distance(center_pos, uv2) * -power * 10.0) * b / atan(-power * b * 10.0);
    }
    return image.Sample(builtin_texture_sampler, uv);
}
 

S4M1R

New Member
Shader works great on my windows pc is not compatible with mac which i need as well, has anyone come across something similar for mac
 

Suslik V

Active Member
Cross-linking the possible solution:
 

fisheyebob

New Member
@5am If there is "Sharpness" filter on mac and you don't use it, then you can replace the shader program of the filter (named "sharpness.effect") by this text:
C:
// Based on Sharpness shader of OBS Studio v27.0.0,
// And https://github.com/Oncorporation/obs-shaderfilter/

uniform float4x4 ViewProj;
uniform texture2d image;

uniform float sharpness;
uniform float texture_width;
uniform float texture_height;

sampler_state def_sampler {
    Filter   = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};

struct VertData {
    float4 pos : POSITION;
    float2 uv  : TEXCOORD0;
};

VertData VSDefault(VertData v_in)
{
    VertData vert_out;
    vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
    vert_out.uv  = v_in.uv;
    return vert_out;
}

float4 PSDrawBare(VertData v_in) : TARGET
{
    int center_x_percent = 50;
    int center_y_percent = 50;
    float power = -sharpness;
    float2 uv_pixel_interval;
    uv_pixel_interval.x = 1.0 / texture_width;
    uv_pixel_interval.y = 1.0 / texture_height;
    float2 center_pos = float2(center_x_percent * .01, center_y_percent * .01);
    float2 uv = v_in.uv;
    float b;
    if (uv_pixel_interval.x < uv_pixel_interval.y){
        b = center_pos.x;
    } else {
        b = center_pos.y;
    }
    uv = center_pos  + normalize(v_in.uv - center_pos) * atan(distance(center_pos, v_in.uv) * -power * 10.0) * b / atan(-power * b * 10.0);
    return image.Sample(def_sampler, uv);
}

technique Draw
{
    pass
    {
        vertex_shader = VSDefault(v_in);
        pixel_shader  = PSDrawBare(v_in);
    }
}

Now the OBS Studio filter named Sharpness will start to act like "unfish" (the sharpness value now controls the amount of the distortion, 0.18 is OK for the image provided by the topic starter).

And keep copy of the original "sharpness.effect" just in case.
Got this working and its great! Thanks. Only thing is, I need it to do the exact opposite correction. I've tried flipping each of the values in here but I'm not sure what I'm looking at. Is it possible to tweak something here to invert the effect?
 
Top