## 4 Conclusions  
In the present study, a computer vision hardware system was presented for the detection of apple pests and diseases. This system was used to classify the apple pests and diseases by means of the image processing techniques, sparse methods, artificial neural networks, and MATLAB software under the controlled conditions (exposure system, camera distance to target, camera angle, and light source). The advantage of this method over the conventional methods is the detection of some common pests and diseases, with low cost and readily available parts. The huge benefit to the farmer for this system is having an advanced tool at their disposal with results comparable to an expert consultant. With the development of the present system, it can also be used in the areas of quarantine, export, and import of agricultural products. In general, the results of this study can be summarized as follows. The results showed that using a combination of computer vision techniques and artificial neural networks and a CCD camera enables the detection of apple pests and diseases with great accuracy without costly, destructive, and time-consuming tests. The detection accuracy of the system using the sparse coding method was 86% for the codling moth of red apple, 72% for the codling moth of golden apple, 83% for _S. pyri_ of red apple, 90% for _S. pyri_ of golden apple, 80% for codling moth and _S. pyri_ of red apple, 67% for codling moth and _S. pyri_ of golden apple, 100% for codling moth and russeeting of golden apple, 80% for _S. pyri_ and russeeting of golden apple, 100% for capsid and codling moth of golden apple, 100% for capsid and _S. pyri_ of golden apple with three views of apples. The higher accuracy was due to an increased number of views. For the capsule of red apple, the detection accuracy of the group using the sparse coding method was 81%, 88% for capsid of golden apple, 85% for russeeting of golden apple, 100% for capsid and russeeting of red apple, and 80% for capsid and russeeting of golden apple. Similar to the previous result, the increased accuracy was due to the increased number of views. The accuracy was obtained from three views of apples for 16 groups of infected apples. The detection accuracy was obtained by a sparse coding method for 2 groups of healthy apples: 97% for a healthy golden apple and 97% for a healthy red apple. In general, this study investigated apple pests and diseases using the proposed algorithm. The algorithm accurately detected 90% of the pests and diseases, which is more accurate and faster than the earlier studies. Although the study was focused on apple diseases, results for this work have huge potential for other crops. In future works, we plan to collect many high-quality images of different types of apple diseases and pests and use the convolution layers of the deep learning models for feature extraction. In addition, other classifiers will be investigated. The following supporting information can be downloaded at: [[https://www.mdpi.com/article/10.3390/app12020906/s1](https://www.mdpi.com/article/10.3390/app12020906/s1)]([https://www.mdpi.com/article/10.3390/app12020906/s1](https://www.mdpi.com/article/10.3390/app12020906/s1)), M-files of sparse approximation, apple classifier, displaying network, and updating network in MATLAB have been attached as Supplementary Materials to the manuscript. The source code is also available at [[https://github.com/jmaja/ApplePestDetector.git](https://github.com/jmaja/ApplePestDetector.git)]([https://github.com/jmaja/ApplePestDetector.git](https://github.com/jmaja/ApplePestDetector.git)). **Author Contributions:** Conceptualization, Y.A.-G., A.A. and M.D. ; methodology, Y.A.-G., M.D., A.A. and J.M.M. ; software, A.A. and Y.A.-G.; validation, Y.A.-G. and J.M.M. ; formal analysis, A.A., Y.A.-G. and J.M.M. ; investigation, Y.A.-G., A.A., M.D. and J.M.M. ; resources, Y.A.-G. and A.A.; data curation, A.A.; writing--original draft preparation, A.A. and Y.A.-G.; writing--review and editing, J.M.M. ; visualization, Y.A.-G. and J.M.M.