Answers.Body: <p>Chessvision.ai actually has an API that it uses to predict the FEN of a position based on an image. If you want to experiment with it, you can see the requests the extension makes after scanning a position in the extension's background console.</p>
  <p>In short, it seems that Chessvision.ai makes a <code>POST</code> request to <code>http://app.chessvision.ai/predict</code> in order to extract the FEN of a chess position, supplying the board orientation, a <code>cropped</code> field which is <code>true</code> if the image was cropped manually and <code>false</code> otherwise, the color of the player that has the move (<a href="https://i.sstatic.net/9nXFbwlK.png" rel="nofollow noreferrer">based on this toggle</a>), the image data (base64 encoded) and a flag to predict the player's turn. For example:</p>
  <pre><code>{
      board_orientation: &quot;predict&quot;
      cropped: false
      current_player: &quot;white&quot;
      image: &quot;data:image/jpeg;base64,...&quot;
      predict_turn: true
  }
  </code></pre>
  <p>If the request is successful, the API returns a JSON object containing the board orientation, the predicted FEN and the predicted turn (can be <code>null</code>). For example:</p>
  <pre><code>{
      board_orientation: &quot;default&quot;
      result: &quot;&lt;fen!&gt;&quot;
      success: true
      turn: &quot;white&quot;
  }
  </code></pre>
  <p>Note that since this API is not publicly documented, it might change at any time.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-29T08:09:58.307Z
Answers.LastActivityDate: 2024-08-29T08:09:58.307Z
Answers.UserDisplayName: double-beep
Body: <p>I'm wanting to create a little screenshot tool that takes a screenshot and outputs an FEN to the clipboard. I was hoping to use chessvision.ai, but it does not seem to have an API that allows me to use it programmatically. What alternatives might suit my needs (accurate conversion from image to FEN, and accessible programmatically i.e. from the command line to be chained with a screenshot tool).</p>
  <p>Note, I've looked at the following two threads:</p>
  <p><a href="https://chess.stackexchange.com/questions/29164/how-can-i-convert-screenshot-capture-into-fen-to-analyse-on-windows-10">How can I convert screenshot capture into FEN to analyse on Windows 10+?</a></p>
  <p><a href="https://chess.stackexchange.com/questions/14601/how-can-i-scan-a-chessboard-and-obtain-its-fen">How can I scan a chessboard and obtain its FEN?</a></p>
  <p>Neither answers my particular question, which is the need to be able to access the image-&gt;FEN conversion tool programmatically.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-06T09:48:38.507Z
Comments.Text: be aware that a screenshot might not have all information. It can be impossible to tell if castling is still allowed or if en passant is possible
Comments.UserDisplayName: Aemyl
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-06T14:13:19.543Z
Comments.Text: Indeed. I was hoping that the algorithm would be able to predict those features of a position, but obviously that would be less than perfect. Still though, fixing those minor details about a position is a vast improvement from having to set up every position you are reading in a book by hand.
Comments.UserDisplayName: av06
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-07T05:55:16.173Z
Comments.Text: There is a open-source project called [Chess Vision](https://github.com/gudbrandtandberg/ChessVision) that is self-hostable
Comments.UserDisplayName: Nicolas Formichella
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-07T06:47:18.447Z
Comments.Text: Is your diagram chess font always the same or does it vary? Obviously, the latter would be horrible even for a neural net.
Comments.UserDisplayName: Hauke Reddmann
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-08-08T00:36:31.287Z
Comments.Text: @HaukeReddmann It should be able to vary. As Nicolas points out, ChessVision can handle this, but I haven't figured out how to use it programmatically.
Comments.UserDisplayName: av06
Tags: <programming><fen><diagram>
Title: Converting image to FEN programmatically
ThreadText: # Converting image to FEN programmatically
  
  (Asked by: username_0 on 2024-08-05)
  
  I'm wanting to create a little screenshot tool that takes a screenshot and outputs an FEN to the clipboard. I was hoping to use chessvision.ai, but it does not seem to have an API that allows me to use it programmatically. What alternatives might suit my needs (accurate conversion from image to FEN, and accessible programmatically i.e. from the command line to be chained with a screenshot tool).
  
  Note, I've looked at the following two threads:
  
  [How can I convert screenshot capture into FEN to analyse on Windows 10+?](https://chess.stackexchange.com/questions/29164/how-can-i-convert-screenshot-capture-into-fen-to-analyse-on-windows-10)
  
  [How can I scan a chessboard and obtain its FEN?](https://chess.stackexchange.com/questions/14601/how-can-i-scan-a-chessboard-and-obtain-its-fen)
  
  Neither answers my particular question, which is the need to be able to access the image->FEN conversion tool programmatically.
  
  **Tags:** programming, fen, diagram
  
  > **Comments:**
  > **username_1**: be aware that a screenshot might not have all information. It can be impossible to tell if castling is still allowed or if en passant is possible  
  > **username_0**: Indeed. I was hoping that the algorithm would be able to predict those features of a position, but obviously that would be less than perfect. Still though, fixing those minor details about a position is a vast improvement from having to set up every position you are reading in a book by hand.  
  > **username_2**: There is a open-source project called [Chess Vision](https://github.com/gudbrandtandberg/ChessVision) that is self-hostable  
  > **username_3**: Is your diagram chess font always the same or does it vary? Obviously, the latter would be horrible even for a neural net.  
  > **username_0**: @HaukeReddmann It should be able to vary. As Nicolas points out, ChessVision can handle this, but I haven't figured out how to use it programmatically.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2024-08-29. Score: 0
  
  Chessvision.ai actually has an API that it uses to predict the FEN of a position based on an image. If you want to experiment with it, you can see the requests the extension makes after scanning a position in the extension's background console.
  In short, it seems that Chessvision.ai makes a POST request to http://app.chessvision.ai/predict in order to extract the FEN of a chess position, supplying the board orientation, a cropped field which is true if the image was cropped manually and false otherwise, the color of the player that has the move (based on this toggle), the image data (base64 encoded) and a flag to predict the player's turn. For example:
  {
      board_orientation: "predict"
      cropped: false
      current_player: "white"
      image: "data:image/jpeg;base64,..."
      predict_turn: true
  }
  
  If the request is successful, the API returns a JSON object containing the board orientation, the predicted FEN and the predicted turn (can be null). For example:
  {
      board_orientation: "default"
      result: ""
      success: true
      turn: "white"
  }
  
  Note that since this API is not publicly documented, it might change at any time.
  
  
  ---
  
  