I want to sum only non zero pixel value, so is there any function in opencv to get that like the function mean(src, mask) as I used sumElmes() but it gives the sum of all values. Any suggestions or any way to solve that eve without builtin functions.