如何使用opencv从市场传单中获取产品图片?

时间:2019-02-27 01:47:45

标签: python opencv machine-learning computer-vision feature-extraction

我如何使用Opencv处理市场传单以提取产品图像? 例如,我有这个市场传单:

Example of market leaflet

Result that I expect

我尝试使用某些图像处理技术,例如bilateralFilter,adaptableThreshold,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)

Example image input

result output

0 个答案:

没有答案