title: The contour detected using opencv to dxf
body: <p>I used opencv to detect contours in Python. I wrote the code for saving this contour as a dxf file as below through a search.</p>
  <pre><code>cap = EasyPySpin.VideoCapture(0)
  
  _, frame = cap.read()
  frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
  frame = cv2.resize(frame, dsize=(0,0), fx=0.26, fy=0.26, interpolation=cv2.INTER_AREA)
  frame_blr = cv2.GaussianBlur(frame, (3, 3), 0)  
  canny = cv2.Canny(frame_blr, 255, 0)
  contours, hierarchy=cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  contours_draw = cv2.drawContours(frame, contours, -1, (0, 255, 0), 1)
  cv2.imshow('contour', contours_draw)
  
  
  contours = [np.squeeze (cnt, axis = 1) for cnt in contours]
  ctr = contours[1]
  dwg = ezdxf.new ('R2010') # create a new DXF R2010 drawing, official DXF version name: 'AC1024'
  msp = dwg.modelspace () # add new entities to the model space
  dwg.layers.new (name = 'MyLines', dxfattribs = {'color': 3}) # 3 = Green
  
  
  for i in range (len (ctr)):
      n = i + 1
      if n&gt;= len (ctr):
          n = 0
      msp.add_line (ctr [i], ctr [n], dxfattribs = {'layer': 'MyLines'}) # add a LINE entity
      print (ctr [i], '-&gt;', ctr [n])
  dwg.saveas ('line.dxf')
  </code></pre>
  <p>But the detected contour and the line drawn in the dxf file are different. Also, a slightly different line is drawn in the dxf file every time it runs.I don't know why.</p>
  <p>Contour Image &gt; <a href="https://i.stack.imgur.com/x7uYl.png" rel="nofollow noreferrer">enter image description here</a>
  DXF file &gt; <a href="https://i.stack.imgur.com/zA4bN.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>And I don't know what this code means.</p>
  <pre><code>contours = [np.squeeze (cnt, axis = 1) for cnt in contours]
  ctr = contours[1]
  </code></pre>
  <p>If I delete this code and edit the crt into contours, the following error occurs.</p>
  <pre><code>Traceback (most recent call last):
    File &quot;c:/Users/MyPc/KHS/p40.contour detection, (x,y).py&quot;, line 38, in &lt;module&gt;
      msp.add_line (contours [i], contours [n], dxfattribs = {'layer': 'MyLines'}) # add a LINE entity
    File &quot;C:\Users\MyPc\AppData\Local\Programs\Python\Python38\lib\site-packages\ezdxf\graphicsfactory.py&quot;, line 121, in add_line
      dxfattribs[&quot;start&quot;] = Vec3(start)
    File &quot;src\ezdxf\acc\vector.pyx&quot;, line 417, in ezdxf.acc.vector.Vec3.__cinit__
  TypeError: invalid argument count
  </code></pre>