マイクロチューブの底にあるデータマトリックス バーコードを読み取ろうとしています。Pythonバインディングを備えたlibdmtxを試しましたが、マトリックスのドットが正方形の場合はかなりうまく機能しますが、ここのように丸い場合はさらに悪化します。
もう 1 つの問題は、場合によってはコード領域に達する輝きです。
バーコードはフラットベッド スキャナーのラックでスキャンされるため、サイズは一定で、ほぼ中央に配置されます。向きはランダムです。
コードを見つけて自分で画像を改善する必要があるという結論に達しました。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()