Counting pulses using SMT32f407VG
Your problem is, that you configured your TIM in encoder mode. An quatrature encoder uses two inputs with 90° phase shifted pulse signals to detect up or down counting. See the red path in the picture below.

So delete :

TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI1,TIM_ICPolarity_Rising, TIM_ICPolarity_Rising );




If you just want a single input pulse counter, you have to use the external trigger (TIMx_ETR) as timer trigger. (green path in the pic)

Add a complete timer initialization and something like:

TIM_SelectInputTrigger(TIM2, TIM_TS_ETRF);