Quasi-Normal frequencies in open cavities: An application to photonic crystals