title: How To Use Yolo txt Files For Detection?
body: <pre><code>import cv2
  import json
  
  def save_yolo_format(image_file, json_file, txt_file):
      with open(json_file) as f:
          chars = json.loads(f.read())
  
      bgr = cv2.imread(image_file)
  
      result = &quot;&quot;
      for char in chars:
          x_center = (char[&quot;x&quot;] + char[&quot;width&quot;] // 2) / bgr.shape[1]
          y_center = (char[&quot;y&quot;] + char[&quot;height&quot;] // 2) / bgr.shape[0]
  
          width = char[&quot;width&quot;] / bgr.shape[1]
          height = char[&quot;height&quot;] / bgr.shape[0]
  
          label = char[&quot;char_id&quot;]
  
          result += str(label) + &quot; &quot; + str(x_center) + &quot; &quot; + str(y_center) + &quot; &quot; + str(width) + &quot; &quot; + str(height) + &quot;\n&quot;
  
      with open(txt_file, &quot;w+&quot;) as f:
          f.write(result)
  
  
  save_yolo_format(&quot;dataset_root/images/1.jpg&quot;,
                   &quot;dataset_root/labels/1.json&quot;,
                   &quot;dataset_root/labels/1.txt&quot;)
  </code></pre>
  <p>**I Convert Json Files To Yolo Txt File **</p>
  <p><a href="https://i.stack.imgur.com/xT6Mt.png" rel="nofollow noreferrer">After Run Code My Result Is...</a></p>
  <p>One Of My Text File Value:</p>
  <p>7 0.05197505197505198 0.5234375 0.07276507276507277 0.26953125</p>
  <p>5 0.13097713097713098 0.51953125 0.08523908523908524 0.25390625</p>
  <p>26 0.23700623700623702 0.51953125-0.12058212058212059 0.32421875</p>
  <p>2 0.3471933471933472 0.5234375 0.08316008316008316 0.28125</p>
  <p>How can I use the files above for detection?</p>