draw Contours

import os
import cv2
import numpy as np

image_file = "./random_1/xQGp1j2BUgXxrXrpTbDORg.jpg"

#bbox = [1456,1922,18,47]
#start=(bbox[0],bbox[1])
#end = (bbox[0] + bbox[2], bbox[1] + bbox[3])

color = (255, 0, 0)
thickness = 2

contours = np.array([ [1472 , 1968 ] , [1464.5 , 1967] , [1461.5,1946],[1460,1943.5], [1457.5,1946], [1455.5,1938], [1465,1921.5], [1469.5, 1923] ,[1473.5, 1932], [1472, 1968.5] ])
print(contours)
contours = contours.reshape(-1,1,2).astype(np.int32)
print(contours)
'''
contours = [
          1472,
          1968.5,
          1464.5,
          1967,
          1461.5,
          1946,
          1460,
          1943.5,
          1457.5,
          1946,
          1455.5,
          1938,
          1465,
          1921.5,
          1469.5,
          1923,
          1473.5,
          1932,
          1472,
          1968.5
        ]
'''
im = cv2.imread(image_file)
image_bbox = cv2.drawContours(im, contours, -1 , color, thickness)

cv2.imwrite("contours.jpg", image_bbox)

  

https://www.coder.work/article/2093359

https://stackoverflow.com/questions/35902139/opencv-3-1-drawcontours-215-npoints-0/35902430

 

https://blog.csdn.net/sinat_29957455/article/details/103297496

 

https://zhuanlan.zhihu.com/p/140514938

https://medium.com/featurepreneur/draw-contours-on-an-image-using-opencv-186b67f87c92

https://learnopencv.com/contour-detection-using-opencv-python-c/

https://stackoverflow.com/questions/57576686/how-to-overlay-segmented-image-on-top-of-main-image-in-python

 

posted on 2021-05-22 21:41  cdekelon  阅读(66)  评论(0)    收藏  举报

导航