我是CV新手,刚学会如何检测纸张边缘。我想尝试更复杂的事情。因此,我从电影网站截图,并希望能够从网站中检测海报。如果背景颜色与海报不同,则可以正常工作。但是当它们的颜色相似时,我就无法通过
结果如下:
cv2.findContours()
找到图片的边缘。
原始图片链接如下:
Poster
我的方法如下:img = cv2.imread('pic5.jpg')
orig = img.copy()
image = orig
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
binary = cv2.medianBlur(gray,3)
# blur = cv2.GaussianBlur(binary, (5, 5), 0)
# ret, binary = cv2.threshold(blur,127,255,cv2.THRESH_TRUNC)
edged = cv2.Canny(binary, 3, 30)
show(edged)
# detect edge
contours, hierarchy = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cnts = sorted(contours, key=cv2.contourArea, reverse=True)[:5]
#
for c in cnts:
# approx
peri = cv2.arcLength(c, True)
eps = 0.02
approx = cv2.approxPolyDP(c, eps*peri, True)
# detect square (4 points)
if len(approx) == 4:
screenCnt = approx
break
res = cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)
show(orig)
结果如下:
我不知道这种方法是否可行。能否基于背景颜色(无论海报的颜色如何)来检测方形部分?