【发布时间】:2018-07-06 17:05:15
【问题描述】:
我想做的是在夜间地球的照片中找到大的光污染区域。我将源照片转换为灰度,然后转换为具有阈值的二进制照片。 cv2.findcontours 工作正常,但是当我试图摆脱小轮廓时,它只会删除其中的一部分。
import cv2
image_orig=cv2.imread('C:\Users\pc\Desktop\middleeast.jpg')
image_gray=cv2.cvtColor(image_orig,cv2.COLOR_BGR2GRAY)
_, image_threshold=cv2.threshold(image_gray,60,255,cv2.THRESH_BINARY)
_,contours,_=cv2.findContours(image_threshold,cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
image_contours=image_orig.copy()
cv2.drawContours(image_contours,contours,-1,(255,255,0),1)
cv2.imshow('image_contours',image_contours)
cv2.imwrite('C:\Users\pc\Desktop\middleEastAllContours.jpg', image_contours)
for counter,contour in enumerate(contours):
if cv2.contourArea(contour)<250.0:
contours.pop(counter)
image_big_contours=image_orig.copy()
cv2.drawContours(image_big_contours,contours,-1,(255,255,0),1)
cv2.imshow('big contours',image_big_contours)
cv2.waitKey(0)
如您所见,轮廓上仍有许多小光污染区域。我怎样才能摆脱它们?
【问题讨论】:
标签: python image opencv contour area