Forums > Gen

Remove shadow during background substraction

April 7, 2012 | 6:42 pm

hi!
i found http://maleesh.wordpress.com/2010/03/18/shadow-removing-with-opencv-2/ i found this article, do you think, that it will be hard to implement it in gen? how to start with it?


April 9, 2012 | 2:08 pm

i did first steps, can you help me please? i need this functionality very much for my next piece..
thank yopu very much!!!

– Pasted Max Patch, click to expand. –

April 9, 2012 | 3:40 pm

ups. here is my last attempt:

– Pasted Max Patch, click to expand. –

January 9, 2013 | 11:25 pm

here a shader port! I think it works a little better.
Thank you!

– Pasted Max Patch, click to expand. –

PS: the maleesh blog is protected by password…

Attachments:
  1. bg.remover.jxs

January 10, 2013 | 4:19 pm

woow! thats a good shader but fails to me and im not a shader wiz… :( any idea? thanks!

– START GLSL INFO LOG: fp –
Fragment shader failed to compile with the following errors:
ERROR: 0:97: error(#160) Cannot convert from: "bool" to: "highp float"
ERROR: 0:98: error(#160) Cannot convert from: "bool" to: "highp float"
ERROR: 0:99: error(#160) Cannot convert from: "bool" to: "highp float"
WARNING: 0:102: warning(#402) Implicit truncation of vector from size: 1 to size: 4
ERROR: 0:105: error(#162) Wrong operand types: no operation "-" exists that takes a left-hand operand of type "const int" and a right operand of type "bool" (or there is no acceptable conversion)
WARNING: 0:106: warning(#402) Implicit truncation of vector from size: 1 to size: 4
ERROR: 0:109: error(#160) Cannot convert from: "bool" to: "highp float"
WARNING: 0:110: warning(#402) Implicit truncation of vector from size: 1 to size: 4
ERROR: 0:113: error(#160) Cannot convert from: "bool" to: "highp float"
WARNING: 0:114: warning(#402) Implicit truncation of vector from size: 1 to size: 4
ERROR: error(#273) 6 compilation errors. No code generated
– END GLSL INFO LOG: fp –
jit.gl.shader: GLSL program failed to compile.


January 10, 2013 | 4:40 pm

on my machine, i get the following errors ….

– START GLSL INFO LOG: fp –
ERROR: 0:91: ‘pow’ : no matching overloaded function found
ERROR: 0:91: ‘pow’ : no matching overloaded function found
ERROR: 0:93: ‘pow’ : no matching overloaded function found
ERROR: 0:97: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:98: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:99: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:102: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
ERROR: 0:105: ‘-’ : wrong operand types no operation ‘-’ exists that takes a left-hand operand of type ‘const int’ and a right operand of type ‘bool’ (or there is no acceptable conversion)
ERROR: 0:105: ‘=’ : cannot convert from ‘const int’ to ‘float’
ERROR: 0:106: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
ERROR: 0:109: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:110: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
ERROR: 0:113: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:114: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
– END GLSL INFO LOG: fp –
jit.gl.shader: GLSL program failed to compile.
– START GLSL INFO LOG: fp –
ERROR: 0:91: ‘pow’ : no matching overloaded function found
ERROR: 0:91: ‘pow’ : no matching overloaded function found
ERROR: 0:93: ‘pow’ : no matching overloaded function found
ERROR: 0:97: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:98: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:99: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:102: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
ERROR: 0:105: ‘-’ : wrong operand types no operation ‘-’ exists that takes a left-hand operand of type ‘const int’ and a right operand of type ‘bool’ (or there is no acceptable conversion)
ERROR: 0:105: ‘=’ : cannot convert from ‘const int’ to ‘float’
ERROR: 0:106: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
ERROR: 0:109: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:110: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
ERROR: 0:113: ‘=’ : cannot convert from ‘bool’ to ‘float’
ERROR: 0:114: ‘=’ : cannot convert from ‘float’ to ’4-component vector of float’
– END GLSL INFO LOG: fp –
jit.gl.shader: GLSL program failed to compile.


January 10, 2013 | 5:14 pm

mmm
I’m not a shader expert but I think:

timtom GPU doesn’t support pow() function and I’ve substitute it with (n*n) instead of pow(n,2).

and yours GPU doesn’t support implicit type conversions so I cast them

try this code.



Accumulator







< ![CDATA[
// http://cycling74.com/forums/topic.php?id=39147 porting
// texcoords
varying vec2 texcoord0;
varying vec2 texcoord1;

// samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

// uniform parameters
uniform int out_mode;
uniform float BD_gt;
uniform float BD_lt;
uniform float CD_squared_lt;

void main() {
vec4 a = texture2DRect(tex0, texcoord0);
vec4 b = texture2DRect(tex1, texcoord1);

float mul_3 = (b.b * a.b);
float add_14 = (((a.r * a.r) + (a.g * a.g)) + (a.b * a.b));
float add_25 = ((b.r * a.r) + (b.g * a.g));
float add_26 = (add_25 + mul_3);
float div_27 = (add_26 / add_14); // importante
float mul_32 = (a.r * (b.r – div_27));
float mul_36 = (a.g * (b.g – div_27));
float add_38 = ((mul_32*mul_32) + (mul_36*mul_36));
float mul_40 = (a.b * (b.b – div_27));
float mul_41 = (mul_40*mul_40);
float add_42 = (add_38 + mul_41); // importante

if (out_mode == 0) {
float gt_29 = float(div_27 > BD_gt);
float lt_28 = float(div_27 < BD_lt);
float lt_43 = float(add_42 < CD_squared_lt);
float mul_44 = (lt_43 * lt_28);
float mul_45 = (mul_44 * gt_29);
vec4 outMx = vec4(mul_45,mul_45,mul_45,mul_45);
gl_FragColor = outMx;
} else if (out_mode == 1) {
float lt_43 = 1-float(add_42 < CD_squared_lt);
vec4 outMx = vec4(lt_43,lt_43,lt_43,lt_43);
gl_FragColor = outMx;
} else if (out_mode == 2) {
float lt_28 = float(div_27 < BD_lt);
vec4 outMx = vec4(lt_28,lt_28,lt_28,lt_28);
gl_FragColor = outMx;
} else if (out_mode == 3) {
float gt_29 = float(div_27 > BD_gt);
vec4 outMx = vec4(gt_29,gt_29,gt_29,gt_29);
gl_FragColor = outMx;
}
}

]]>



MIB
January 10, 2013 | 6:21 pm

I get these errors. Any idea what they are??

– START GLSL INFO LOG: fp –
ERROR: 0:105: ‘-’ does not operate on ‘int’ and ‘float’
ERROR: 0:106: Use of undeclared identifier ‘lt_43′
ERROR: 0:106: Use of undeclared identifier ‘lt_43′
ERROR: 0:106: Use of undeclared identifier ‘lt_43′
ERROR: 0:106: Use of undeclared identifier ‘lt_43′
ERROR: 0:107: Use of undeclared identifier ‘outMx’
– END GLSL INFO LOG: fp –
jit.gl.shader: GLSL program failed to compile.


January 11, 2013 | 1:57 am

YES! thanks esnho the new one compiles fine! and even better banging the background matrix.. :)

im only getting some good results chossing out_mode 1 and tweaking param CD_squared_lt
with the other modes 0,2 or 3 seems nothing happens.. can you explain a little bit the params?

cheers!


January 11, 2013 | 1:37 pm

@MIB: did you try the last version?

@carsol: I’ve done just a copy and paste porting… maybe ćwiek can explain those parameters or the password protected blog linked by him… sorry. If you try the ćwiek you’ll notice that the modes are porting for the four outlets of the gen patch.


January 12, 2013 | 1:40 am

I’ve found this article, is not the same algorithm but it looks similar and it seems to work well, but I did not any implementations of this.

http://www.tuicool.com/articles/Y3amyq


January 15, 2013 | 9:42 pm

We are not talking about gen no more so, I put in a GEN patch and the relative shader patch, it’s a really simple background subtraction patch.

Here is the patch, it contains the GEN and shader version:

– Pasted Max Patch, click to expand. –

I made a lot of confusion in this post, please forgive me.

Attachments:
  1. bg.remover3.jxs

Viewing 12 posts - 1 through 12 (of 12 total)