The gesture's code with opencv doesn't count the finger

I tried to put your code row inside the mine, but it doesn’t count well the finger in the video. Why?