Opencv cv2.drawcontours КонтурPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Opencv cv2.drawcontours Контур

Сообщение Anonymous »

my input:

Мой код:

Код: Выделить всё

# import the necessary packages
import numpy as np
import argparse
import imutils
import cv2

print("Your OpenCV version: {}".format(cv2.__version__))
print("Are you using OpenCV 2.X? {}".format(imutils.is_cv2()))
print("Are you using OpenCV 3.X? {}".format(imutils.is_cv3()))
print("Are you using OpenCV 4.X? {}".format(imutils.is_cv4()))

# load the image
image_orig = cv2.imread('box1.jpg')
height_orig, width_orig = image_orig.shape[:2]

# cv2.imshow('image_orig' , image_orig)
# cv2.waitKey(0)
cv2.imwrite('image_orig.png', image_orig)

# copy of original image
image_to_process = image_orig.copy()

image_gray = cv2.cvtColor(image_to_process, cv2.COLOR_BGR2GRAY)
image_gray = cv2.GaussianBlur(image_gray, (5, 5), 0)

# cv2.imshow('image_gray' , image_gray)
# cv2.waitKey(0)
cv2.imwrite('image_gray.png', image_gray)

# perform edge detection, then perform a dilation + erosion to close gaps in between object edges
image_edged = cv2.Canny(image_gray, 50, 100)
image_edged = cv2.dilate(image_edged, None, iterations=1)
image_edged = cv2.erode(image_edged, None, iterations=1)

# cv2.imshow('image_edged' , image_edged)
# cv2.waitKey(0)
cv2.imwrite('image_edged.png', image_edged)

# find contours in the edge map
cnts = cv2.findContours(image_edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

cnts = cnts[1] if imutils.is_cv2() else cnts[0] #### #### using CV4

print(len(cnts))

# loop over the contours individually

# prints contours in red color  thickness = 1
image_contours = image_to_process.copy()
for c in cnts:

cv2.drawContours(image_contours, c , -1 ,(0,0,255),1)

cv2.imshow('1', image_contours)
cv2.waitKey(0)

# prints contours in red color  thickness = 10
image_contours = image_to_process.copy()
for c in cnts:

cv2.drawContours(image_contours, c , -1 ,(0,0,255),10)

cv2.imshow('10', image_contours)
cv2.waitKey(0)

# prints contours in red color  thickness = cv2.FILLED
image_contours = image_to_process.copy()
for c in cnts:

cv2.drawContours(image_contours, c , -1 ,(0,0,255), cv2.FILLED)

cv2.imshow('filled', image_contours)
cv2.waitKey(0)

# prints contours in red color  thickness = cv2.FILLED
image_contours = image_to_process.copy()
for c in cnts:

cv2.drawContours(image_contours, [c] , -1 ,(0,0,255), cv2.FILLED)

cv2.imshow('filled_[]', image_contours)
cv2.waitKey(0)
output:

Любая конкретная причина:

Код: Выделить всё

cv2.drawContours(image_contours, [c] , -1 ,(0,0,255), cv2.FILLED)

работает, пока

Код: Выделить всё

cv2.drawContours(image_contours, c , -1 ,(0,0,255), cv2.FILLED)

нет, и почему

Код: Выделить всё

cv2.drawContours(image_contours, c , -1 ,(0,0,255), 10)
сделать работу?
Какой из них правильный способ кодировать? Я что -нибудь упускаю?

Подробнее здесь: https://stackoverflow.com/questions/796 ... vs-contour
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»