Вот код, который я использовал
import cv2
import numpy as np
img = cv2.imread('circle.png' )
imgray = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY)
imgblured = cv2.GaussianBlur(imgray , (5,5) , 0)
_,threshold = cv2.threshold(imgblured,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU )
_,contours,_=cv2.findContours(threshold , cv2.RETR_LIST ,cv2.CHAIN_APPROX_SIMPLE)
print 'number of contours is : ' , len(contours)
cnt = contours[0]
cv2.drawContours(img , [cnt] , -1 , (255,255,255),20)
Эта часть представляет расстояние цветом. Думаю, мне нужна дополнительная помощь.
for i in range ( img.shape[0]):
for j in range (img.shape[1]):
dist = cv2.pointPolygonTest( cnt ,(i,j) , True)
if dist > 0 :
img[i,j] =[j,0,0]
elif dist == 0 :
continue
else :
img[i,j] =[0,0,j]
Заранее спасибо .