# Motion Control System of Unmanned Railars Based on Image Recognition
## 4 Experiment Results  
### Introduction to Testing Program  
After setting up our experiment facility, the test program was run to verify the proposed method. When the program starts to execute, the model railcar is given 55% of its power to run smoothly. At the same time, an input interface window, as shown in Figure 7, jumps out onto the screen. The input interface can take the commands of four different users, these being \"a\", \"d\", \"s\" and \"t\", where \"a\" stands for accelerate, \"d\" for decelerate, \"s\" for stop and \"t\" for turn around. Figure 6: The experiment facility. Figure 7: Input interface window. When the model railcar is running, its wireless CMOS camera starts to send captured consecutive images to the PC. Meanwhile, a window on the PC screen as shown in Figure 8 will jump out to display the consecutive images being received from the wireless CMOS camera. The received consecutive images are pre-processed using utilities provided by OpenCV. The images are first converted to a gray level image using cv2.cvtColor. Secondly, applying a Gaussian filter using cv2.GaussianBlur will reduce the noise of these gray level images. The function convolves the source image with the specified Gaussian kernel. In the third step, the cv2.equalizeHist function is utilized to equalize the histogram of grayscale images so that the levels of brightness are normalized and the contrast of the images are increased. Since the accuracies of the trained strong classifiers are not 100%, all four predefined signs, these being, accelerating, decelerating, stopping and reversing, should be detected at least three times in consecutive images within 0.2 of a second before the system confirms the detections. This method can filter out any false detection, which just acts like a glitch. As shown in Figure 9, when the detections are confirmed, the detected signs will be enclosed by different color rectangles with proper text notations to describe which predefined sign it is. Almost simultaneously, the motion PWM command corresponding to the detected predefined sign is transferred to the Arduino UNO R3 board and its L298n motor driving module in order to control the motion of the N scale (1/150) model railcar. For the model railcar, if the given power is over 95%, it could run too fast and go off the rails. Therefore, the allowed maximum power in the program is set at 95%. On the other hand, if the power is below 35%, the model railcar cannot go further. The required minimum power in the program is set at 35% Every time when an acceleration sign is detected, the power is increased by 10% until the maximum of allowed power, which is 95%, is reached, to ensure that the model railcar will not go off the rails. Similarly, every time that a deceleration sign is detected, the power is decreased by 10% until the minimum of required power of 35% is reached. When a stop sign is detected, the power immediately drops to zero to stop the model railcar. When a reverse sign is detected, program will reverse the model railcar's moving direction by setting digital inputs IN1 to zero, and IN2 to one on the Arduino L298n motor driving module so that the model railcar can immediately reverse, and also increase its power by 10% to quickly move away from its original direction. In the experiment, we deployed four predefined signs to do the full functional verification. The railcar first detected the acceleration sign and it did accelerate accordingly. Then it detected the deceleration sign, and the speed was slowed down as expected. Followed by its detection of the reverse sign, the train shortly stopped and turned around to move in the opposite direction. When the railcar was moving in the opposite direction, the camera was in its tail. When the tail camera detected both deceleration and acceleration signs again, the railcar had according responses. It kept moving until the camera detected a stop sign and the railcars immediately stopped.