我正在寻找一个如何在python中使用OpenCV的ConnectedComponentsWithStats()函数的示例,请注意,这仅适用于OpenCV 3或更高版本.官方文档仅显示了C++的API,即使在为python编译时该函数存在.我无法在网上找到它.
我是 CV 的新手,我刚刚学会了如何检测论文的边缘。我想尝试更复杂的东西。所以我从电影网站制作了一个截图,并想从网站上检测海报。如果背景颜色与海报不同,则效果很好。但是当它们颜色相似时,我找不到图片的边缘 原图
cv2.findContours()
是:
海报
而我所做的是:
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) …Run Code Online (Sandbox Code Playgroud) python opencv image-processing computer-vision deep-learning