在不同位置绘制轮廓

时间:2019-02-05 12:33:26

标签: python opencv image-processing opencv-drawcontour

我想在空白图像的中间绘制轮廓。我不知道如何设置要绘制的轮廓位置。这是我使用的线。

cv2.drawContours(bimg, c, -1, 255, 1)

bimg是空白图像,c是我从图像中提取的轮廓。我相信可以通过操作c来移动轮廓,但是我不明白c的实际写法

1 个答案:

答案 0 :(得分:0)

您可以查看contours的opencv官方文档。该代码可用于查找图像阈值的轮廓并将其绘制在带有红色的白色背景上。

img = cv2.imread('image_name.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
_, cnts, _ = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
bgr = np.ones((img.shape[0], img.shape[1]), dtype= 'uint8')*255 #this creates a white background of the same size of input shape
cv2.drawContours(bgr, cnts, -1, (0,0,255), 1)