To achieve healthy and optimal yields of agricultural products, the principles of nutrition must be observed and appropriate fertilizers must be applied. Nutritional deficiencies or overabundance reduce the quality and yield of the products. Thus, their early detection prevents physiological disorders and associated diseases. Most research efforts have focused on spectroscopy, which extracts only spectral data from a single point of the product. The present study aims to detect early excess nitrogen in cucumber plants by using a new hyperspectral imaging technique based on a hybrid of artificial neural networks and the imperialist competitive algorithm (ANN-ICA), which can provide spectral and spatial information on the leaves at the same time. First, cucumber seeds were planted in 18 pots. The same inputs were applied to all the pots until the plants grew; after that, 30% excess nitrogen was applied to nine pots with irrigation water, while it remained constant in the other nine pots. Each day, six leaves were collected from each pot, and their images were captured using a hyperspectral camera (in the range of 400–1100 nm). The wavelengths of 715, 783 and 821 nm were determined as the most effective for early detection of excess nitrogen using a hybrid of artificial neural networks and the artificial bee colony algorithm (ANN-ABC). The parameter of days of treatment was classified using ANN-ICA. The performance of the classifier was evaluated using different criteria, namely recall, accuracy, specificity, precision and the F-measure. The results indicate that the differences between different days were statistically significant. This means that the hyperspectral imaging technique was able to detect plants with excess nitrogen in the near-infrared range (NIR), with a correct classification rate of 96.11%.