Measurement of inelastic J/psi and psi ' photoproduction at HERA