python读取定位_如何使用python定位和读取Data Matrix代码

本文介绍了如何使用Python结合OpenCV库来处理和读取Data Matrix条形码,特别是在遇到圆形点和图像反光问题时。通过阈值处理、轮廓查找和最小外接矩形等步骤,实现对条形码的定位和优化。
摘要由CSDN通过智能技术生成

我正在尝试读取微管底部的数据矩阵条形码.我试过

libdmtx有python绑定并且当矩阵的点是正方形时工作得相当好但是当它们像这里一样圆时更糟糕:

另一个复杂因素是闪耀,在某些情况下到达代码区域.

条形码在平板扫描仪上的架子中扫描,因此它们具有恒定的尺寸并且大致居中.方向是随机的.

我得出结论,我必须自己找到代码并改善图像.我使用python和OpenCV 3.1.我已经尝试过阈值处理,轮廓:

import matplotlib.pyplot as plt

import numpy as np

import cv2

well = plt.imread('https://i.stack.imgur.com/kqHkw.png')

well = cv2.cvtColor(well, cv2.COLOR_BGRA2GRAY)

plt.subplot(151); plt.imshow(well)

x, thr = cv2.threshold(well, .4[enter image description here][2], 1, cv2.THRESH_BINARY)

thr = np.uint8(thr)

plt.subplot(152); plt.imshow(thr)

dst, contours, hierarchy = cv2.findContours(thr.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

c = cv2.drawContours(np.zeros_like(thr), contours, -1, 255, 1)

plt.subplot(153); plt.imshow(c)

areas = map(lambda x: cv2.contourArea(cv2.convexHull(x)), contours)

max_i = areas.index(max(areas))

d = cv2.drawContours(np.zeros_like(thr), contours, max_i, 255, 1)

plt.subplot(154); plt.imshow(d)

rect = cv2.minAreaRect(contours[max_i])

box = cv2.boxPoints(rect)

box = np.int0(box)

e = cv2.drawContours(np.zeros_like(thr),[box],0,255,1)

plt.subplot(155); plt.imshow(e)

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值