Answers.Body: <p>Option 1 would be a very interesting one from a research perspective. I cannot imagine that CNNs have to capacity at the moment, to learn the concept of numbers and apply them in a useful way. If it was an analog speedometer, things would be different. But it would be really interesting to try it and see what you can achieve with this approach. I haven't read any research papers yet, where such a challenge would have been mastered.</p>
  
  <p>If you are less concerned with research but rather get this project to work, I would propose an approach similar to option 2. The OCR tools you mentioned were designed to identify symbols, even if distorted or otherwise hard to read. In your case, the numbers will always look the same and are most likely always in fixed positions. Therefore, using fancy OCR algorithms or neural nets are overkill for the problem at hand. You can write a simple algorithm that crops the speedometer, searches for the 10 possible patterns (0 to 9) with 10 specific kernels and calculate the speed from the result. This can be implemented efficiently without the need to train a CNN or some other complex algorithm.</p>
  
  <hr>
  
  <p>Method for implementation:</p>
  
  <p>To answer the first question in the comments. The algorithm for this is really easy. Your image will be represented by a 2D array (or maybe a 3D array if you are working with colors). All you need to do is find out, what your numbers look like and store the appropriate array. You should end up with 10 different arrays for 10 different numbers.</p>
  
  <p>To find out if a number is in your current picture, you only have to check if the array for this number is a subset of the array of your current picture. The position, where the arrays are matching, will also indicate the position of the number. You do this for all 10 numbers and can calculate the actual value displayed on the speedometer afterwards from the results.</p>
  
  <p>This is very easy if the numbers always look exactly identical. In this case you can simply look for an exact match. If there are slight variations, you can look for parts of the image array that is similar to your template arrays. Just sum the absolute values of the diffs of each pixel value and if it is below a certain threshold, you have your match. That's all there is to it.</p>
  
  <p>In python I like working with <a href="http://effbot.org/imagingbook/pil-index.htm" rel="nofollow noreferrer">PIL</a> for this kind of image manipulation, but there are other frameworks out there as well.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T15:48:16.960Z
Answers.Text: I would be glad if you could provide me with some links/search terms on how to implement the mentioned algorithm that searches for the patterns. I'm relatively new to python/OCRs.
Answers.UserDisplayName: TheJD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T16:41:58.057Z
Answers.Text: @TheJD I edited my answer to address your question. It is a very simple approach based on the underlying matrices of the images. If my explanations above didn't help, let me know!
Answers.UserDisplayName: Demento
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T17:19:07.663Z
Answers.Text: Thank you very much! My only concern was on how to counter slight differences in the images, due to a semi-transparent speedometer. I might have to apply a threshold in order for the digits to stand out. As the digits are in fixed places, and the car never exceeds 250 mph, the maximum number of scans seems to be 3+10+10=23, right? Please correct me, if I'm wrong!
Answers.UserDisplayName: TheJD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T17:37:28.950Z
Answers.Text: @TheJD Yes, you are exactly right!
Answers.UserDisplayName: Demento
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T17:42:19.607Z
Answers.Text: I'm going to try this as soon as possible, and give feedback, wether it worked. Now I wonder, whether I should normalize the speed (e.g. divide it by 250) before feeding it to the fully contected layer.
Answers.UserDisplayName: TheJD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-13T05:56:12.957Z
Answers.LastActivityDate: 2017-09-13T16:40:46.610Z
Answers.LastEditDate: 2017-09-13T16:40:46.610Z
Answers.UserDisplayName: Demento
Body: <p>I'm developing a game AI, which tries to master racing simulations. I already trained a CNN (AlexNet) on in-game footage of me playing the game and the pressed keys as the target. As the CNN is only making predictions on a frame-to-frame basis, and I resized the image input to 160x120 due to GPU memory limitations, it cannot read the speedometer, so it seems not to have a feeling for its current velocity.</p>
  <p>I thought of different ways to fix this issue:</p>
  <ol>
  <li><p>Crop the captured image down to the size of the speedometer, which displays the current speed in mph, and feed the low-resolution game image, as well as the relatively high-res image (70x30) of the current speed into the neural network, which makes predictions based on the two images.</p>
  </li>
  <li><p>As I don't know whether AlexNet can serve as an OCR as well, my second thought was to use an existing one (like tesseract-ocr/PyTesser) on the cropped image and feed its output to the fully connected layer.</p>
  </li>
  <li><p>I already tried to implement an optical-flow algorithm, but, sadly, non of the Python ones seems to output good real-time results. I wonder whether I can input the current frame as well as the last one, and let AlexNet figure out the movement.</p>
  </li>
  </ol>
  <p>As the processing has to happen in real-time, and the only performance reviews of pytesser I found reported a processing time of ~100ms (never tested that).</p>
  <p>My question is: what method would work best?</p>
  <p>The optical flow approach would have the advantage of the AI knowing in which direction other cars are moving as well.</p>
  
Tags: <convolutional-neural-networks><game-ai><optical-character-recognition><alexnet><optical-flow>
Title: How should the racing agent take into account the velocity of the vehicle, given the images with a speedometer?
UserDisplayName: TheJD
ThreadText: # How should the racing agent take into account the velocity of the vehicle, given the images with a speedometer?
  
  (Asked by: username_0 on 2017-09-12)
  
  I'm developing a game AI, which tries to master racing simulations. I already trained a CNN (AlexNet) on in-game footage of me playing the game and the pressed keys as the target. As the CNN is only making predictions on a frame-to-frame basis, and I resized the image input to 160x120 due to GPU memory limitations, it cannot read the speedometer, so it seems not to have a feeling for its current velocity.
  
  I thought of different ways to fix this issue:
  
  1. Crop the captured image down to the size of the speedometer, which displays the current speed in mph, and feed the low-resolution game image, as well as the relatively high-res image (70x30) of the current speed into the neural network, which makes predictions based on the two images.
  2. As I don't know whether AlexNet can serve as an OCR as well, my second thought was to use an existing one (like tesseract-ocr/PyTesser) on the cropped image and feed its output to the fully connected layer.
  3. I already tried to implement an optical-flow algorithm, but, sadly, non of the Python ones seems to output good real-time results. I wonder whether I can input the current frame as well as the last one, and let AlexNet figure out the movement.
  
  As the processing has to happen in real-time, and the only performance reviews of pytesser I found reported a processing time of ~100ms (never tested that).
  
  My question is: what method would work best?
  
  The optical flow approach would have the advantage of the AI knowing in which direction other cars are moving as well.
  
  **Tags:** convolutional-neural-networks, game-ai, optical-character-recognition, alexnet, optical-flow
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-09-13. Score: 0 | Accepted answer
  
  Option 1 would be a very interesting one from a research perspective. I cannot imagine that CNNs have to capacity at the moment, to learn the concept of numbers and apply them in a useful way. If it was an analog speedometer, things would be different. But it would be really interesting to try it and see what you can achieve with this approach. I haven't read any research papers yet, where such a challenge would have been mastered.
  
  If you are less concerned with research but rather get this project to work, I would propose an approach similar to option 2. The OCR tools you mentioned were designed to identify symbols, even if distorted or otherwise hard to read. In your case, the numbers will always look the same and are most likely always in fixed positions. Therefore, using fancy OCR algorithms or neural nets are overkill for the problem at hand. You can write a simple algorithm that crops the speedometer, searches for the 10 possible patterns (0 to 9) with 10 specific kernels and calculate the speed from the result. This can be implemented efficiently without the need to train a CNN or some other complex algorithm.
  
  ---
  
  Method for implementation:
  
  To answer the first question in the comments. The algorithm for this is really easy. Your image will be represented by a 2D array (or maybe a 3D array if you are working with colors). All you need to do is find out, what your numbers look like and store the appropriate array. You should end up with 10 different arrays for 10 different numbers.
  
  To find out if a number is in your current picture, you only have to check if the array for this number is a subset of the array of your current picture. The position, where the arrays are matching, will also indicate the position of the number. You do this for all 10 numbers and can calculate the actual value displayed on the speedometer afterwards from the results.
  
  This is very easy if the numbers always look exactly identical. In this case you can simply look for an exact match. If there are slight variations, you can look for parts of the image array that is similar to your template arrays. Just sum the absolute values of the diffs of each pixel value and if it is below a certain threshold, you have your match. That's all there is to it.
  
  In python I like working with [PIL](http://effbot.org/imagingbook/pil-index.htm) for this kind of image manipulation, but there are other frameworks out there as well.
  
  > **Comments:**
  > **username_0**: I would be glad if you could provide me with some links/search terms on how to implement the mentioned algorithm that searches for the patterns. I'm relatively new to python/OCRs.  
  > **username_1**: @username_0 I edited my answer to address your question. It is a very simple approach based on the underlying matrices of the images. If my explanations above didn't help, let me know!  
  > **username_0**: Thank you very much! My only concern was on how to counter slight differences in the images, due to a semi-transparent speedometer. I might have to apply a threshold in order for the digits to stand out. As the digits are in fixed places, and the car never exceeds 250 mph, the maximum number of scans seems to be 3+10+10=23, right? Please correct me, if I'm wrong!  
  > **username_1**: @username_0 Yes, you are exactly right!  
  > **username_0**: I'm going to try this as soon as possible, and give feedback, wether it worked. Now I wonder, whether I should normalize the speed (e.g. divide it by 250) before feeding it to the fully contected layer.  
  
  ---
  
  