Open CV running error

and how could that happen?

perhaps the loop that sets this variable, runs zero times.

please learn to debug python code.