## 3 Methodology
### Working Status Recognition  
The study proposes a novel text recognition method combining HOG and CRNN to accurately and efficiently identify the working status of the CNC machine. This method consists of two stages: text detection using projection-based segmentation [23], and text recognition using convolutional recurrent neural network. The proposed segmentation algorithm has three steps. First, the projection scans horizontally to determine the upper and lower bounds of the text area. Second, the projection scans vertically to define the left and right bounds of the text area, and then bounding boxes containing the text information are generated. Finally, the non-text regions are removed and the feature maps of text regions are extracted for recognition. Before applying this segmentation algorithm, some pre-processing steps are adopted. First, transform the color images into grayscale images. The pixel value is from 0 to 255 in a grayscale image. Second, the binarization will convert the grayscale images to binary images using thresholding. Pixels with a greater value than the threshold \(P\) are replaced with white color and other pixels are replaced with black color. Here the value of the black pixel is set to one, and the value of the white pixel is set to zero. That is:  
\[ \begin{split} Value(i,j)=1,\,pixel(i,j)<P\\ Value(i,j)=1,\,pixel(i,j)>P\\ (0<i<\text{width, }0<j<\text{height})\end{split}  \tag{4}\]Width and height are two image parameters, and \(m\) is a variable threshold according to the image background color. The number of black pixels accounts by the Equation:  
\[pixelRow[j]=\sum_{i=\frac{N}{N}\times\text{width}}^{\frac{m+1}{N}\times\text{ width}}Value(i,\,j)(0\,<\,j\,<\,\text{height},m=0,1,2,\ldots N-1) \tag{5}\]  
Here divide the whole image into \(N\) parts with the same height and width. Then, an appropriate threshold \(Q\) is set to separate the text and non-text pixels. In the Equation (6), when _pixelRow [j]_ > \(Q\), it is set to one, otherwise it is set to zero:  
\[ \begin{array}{c}\text{\emph{Horizontal [j]}}=1,\,\text{\emph{pixelRow[j]}}>Q\\ \text{\emph{Horizontal [j]}}=1,\,\text{\emph{pixelRow[j]}}<Q\\ \text{\emph{(0<j<height)}}\end{array}  \tag{6}\]  
_Horizontal [j]_ is calculated, traversing the entire array. When the array's value changes from zero to one, record this pixel as the start point. When the array's value changes from one to zero, record this pixel as the endpoint. Finally, the text bounding boxes are generated. After text detection, CRNN [24] is used to recognize the detected text. The framework of CRNN used in this study is shown in Figure 3. It consists of three subnetworks: convolutional layer, recurrent layer, and transcription layer. The convolutional layer automatically extracts feature map sequences from input images. Then the extracted feature sequences are fed into the recurrent network to predict each feature sequence. The transcription layer is used to translate each frame prediction generated in the recurrent layer and group them into a labeled sequence. The main benefit of the CRNN is that it can be trained with one loss function despite being composed of different network architectures. Figure 3: The architecture of CRNN. The convolutional layer in CRNN is modified from a standard CNN model by removing the fully connected layers. It extracts feature map representation from an input image. All the input images are scaled to the same size in the pre-processing step. Then feature vector sequence is obtained after the feature maps are extracted in the convolutional layer. To keep the order of the text unchanged, each feature vector is generated from left to right on the feature maps, and the \(i\)-th feature vector is the concatenation of the \(i\)-th columns of all the feature maps. Finally, those sequences will be fed into the recurrent layer as inputs. The feature maps are divided into many rectangle regions with a fixed width, which is the receptive fields.