我只想填充中間的人行橫道,而不是影像的所有邊緣。我該怎么做?
import numpy as np
import cv2 as cv2
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc('axes', labelsize=14)
mpl.rc('xtick', labelsize=12)
mpl.rc('ytick', labelsize=12)
#Routine to fix
def fixColor(img):
return(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
img = cv2.imread("walk.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
plt.imshow(fixColor(blurred))
canny = cv2.Canny(blurred, 30, 300)
plt.imshow(fixColor(canny))
(cnts, _) = cv2.findContours(canny.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
coins = image.copy()
cv2.drawContours(coins, cnts, -1, (255, 0, 0), 2)
plt.imshow(fixColor(coins))
結果:
注意:為了用您選擇的顏色填充輪廓,其中的thickness引數cv2.drawContours()必須為 -1。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/468452.html
上一篇:從t1中選擇所有行joint2onid并從t2中選擇最小值,如果沒有則選擇null
下一篇:在迭代散點圖旁邊繪制自定義顏色圖
