2017-07-05 12 views
2

マイクロチューブの底にあるデータマトリックスバーコードを読み取ろうとしています。Pythonでデータマトリックスコードを見つけて読み取る方法

datamatrix sample

別の合併症はいくつかのケースでは、コードに到達した輝きがある:私はPythonバインディングを持っており、行列のドットが正方形であるが、彼らはここにラウンドしているときずっと悪いときも合理的に働くlibdmtxを試してみましたエリア。

バーコードは、フラットベッドスキャナーのラックでスキャンされ、一定のサイズでほぼ中央に配置されます。方向はランダムです。

私は結論に達しましたコードを見つけて自分でイメージを改善する必要があります。私は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() 

result

+1

それは[伝えどちらかのラウンドの要素をサポートしていない]ので、私も(https://stackoverflow.com/a/35017291/603323)zxingしようとしませんでした。 – Mische

答えて

5

それはハリスのコーナー検出器(B)は、適切な設定で非常によく丸い要素を見つけることが判明しました。

result image here

(C)を閾値処理したところ、得られた領域の輪郭を検出します。最大輪郭(D)を選択し、最小限の境界ボックス(E)を見つける。

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.title('A') 
plt.imshow(well) 

harris = cv2.cornerHarris(well,4, 1,0.00) 
plt.subplot(152); plt.title('B') 
plt.imshow(harris) 

x, thr = cv2.threshold(harris, 0.1 * harris.max(), 255, cv2.THRESH_BINARY) 
thr = thr.astype('uint8') 
plt.subplot(153); plt.title('C') 
plt.imshow(thr) 

dst, contours, hierarchy = cv2.findContours(thr.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 
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.title('D') 
plt.imshow(d) 

rect =cv2.minAreaRect(contours[max_i]) 
box = cv2.boxPoints(rect) 
box = np.int0(box) 
e= cv2.drawContours(well,[box],0,1,1) 
plt.subplot(155); plt.title('E') 
plt.imshow(e) 

plt.show() 
+1

は、解決策が見つかると答えたことを感謝します。 – Mayank

関連する問題