Ab initio approach to the ferroelectric properties of ABO3 perovskites: the case of KNbO3