如何使用 Opencv 处理市场传单以提取产品图像?例如,我有这个市场传单:
我尝试使用一些图像处理技术,如双边过滤器、自适应阈值、findContours,但效果不佳,因为我必须更改一些参数才能在其他市场传单中工作。
我正在考虑使用 ORB、SURF 和/或 FREAK 并抓取一些产品图像以提取特征,然后构建这些特征的数据库。
我从市场传单中提取产品图像的算法示例:
img = cv2.imread(image)
grayImage = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.bilateralFilter(grayImage, 20, 21, 21)
threshold = cv2.adaptiveThreshold(blur, 250, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 249, 0)
_, contours, _ = cv2.findContours(threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
hullContours = []
for cnt in contours:
rect = cv2.minAreaRect(cnt)
box = cv2.boxPoints(rect)
hullContours.append(np.int0(box))
hullContours = [c for c in hullContours if 200 < cv2.contourArea(c) ]
for c in hullContours:
cv2.drawContours(img, [c], -1, (0, 0, 0), 2)
cv2.imshow("Image",img)
cv2.waitKey(0)