Creating your own contour in opencv using python

前端 未结 4 603
长情又很酷
长情又很酷 2021-02-07 07:00

I have a set of boundary points of an object.

I want to draw it using opencv as contour.

I have no idea that how to convert my points to contour representation.

4条回答
  •  爱一瞬间的悲伤
    2021-02-07 07:29

    To add to Cherif KAOUA's answer, I found I had to convert to list and zip my numpy array. Reading in an array of points from a text file:

      contour = []
      with open(array_of_points,'r') as f:
          next(f) // line one of my file gives the number of points
          for l in f:
              row = l.split()
              numbers = [int(n) for n in row]
              contour.append(numbers)
    
      ctr = np.array(contour).reshape((-1,1,2)).astype(np.int32)
      ctr = ctr.tolist()
      ctr = zip(*[iter(ctr)]*len(contour))
    

提交回复
热议问题