The use of UAVs for photogrammetry has risen recently, often focusing on horizontal terrains. However, slopes affect image overlap and ground sample distance (GSD). This study proposes an AI-based method to classify terrain into meadows, slopes, or valleys, then autonomously plans flights adjusting altitude to keep GSD constant. Implemented on the Nvidia Jetson TX2 as companion computer. This single-board computer (SBC) uses Linux and ROS, it integrates with a Pixhawk 2 flight controller in a hardware-in-the-loop setup to verify performance. Results show an improvement in GSD deviation, which was from 89% at baseline to less than 20% using the method.