コードスキャン認識
ビデオチュートリアル15 - コードスキャン認識: https://singtown.com/learn/50017/
QRコード
http://cli.im/\ このサイトを使えば、任意の内容のQRコードを生成できます。

import csi, image
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QQVGA) # M7 では QVGA も使用可能...
csi0.snapshot(frames=30)
csi0.auto_gain(False) # 画像の白飛びを防ぐため、これをオフにする必要があります...
while(True):
img = csi0.snapshot()
img.lens_corr(1.8) # 2.8mm レンズには強度1.8が適しています。
for code in img.find_qrcodes():
print(code)

{x:46, y:38, w:78, h:81, payload:"openmv", version:1, ecc_level:2, mask:6, data_type:4, eci:0}
バーコード
http://barcode.tec-it.com/zh/Code128?data=OpenMV\ このサイトを使ってバーコードを生成できます。
import csi, image, time, math
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.VGA) # 高解像度!
csi0.window((640, 80)) # 垂直解像度80は処理負荷が少ない(40ならさらに2倍速)。
csi0.snapshot(frames=30)
csi0.auto_gain(False) # 画像の白飛びを防ぐため、これをオフにする必要があります...
csi0.auto_whitebal(False) # 画像の白飛びを防ぐため、これをオフにする必要があります...
clock = time.clock()
# バーコード検出は、OpenMV Cam の OV7725 カメラモジュールのフル解像度である 640x480 で
# 実行できます。バーコード検出は RGB565 モードでも動作しますが、その場合は解像度が
# 低くなります。とはいえ、バーコード検出を良好に機能させるには高い解像度が必要なので、
# 常にグレースケールの 640x480 で実行することを推奨します...
def barcode_name(code):
if(code.type == image.EAN2):
return "EAN2"
if(code.type == image.EAN5):
return "EAN5"
if(code.type == image.EAN8):
return "EAN8"
if(code.type == image.UPCE):
return "UPCE"
if(code.type == image.ISBN10):
return "ISBN10"
if(code.type == image.UPCA):
return "UPCA"
if(code.type == image.EAN13):
return "EAN13"
if(code.type == image.ISBN13):
return "ISBN13"
if(code.type == image.I25):
return "I25"
if(code.type == image.DATABAR):
return "DATABAR"
if(code.type == image.DATABAR_EXP):
return "DATABAR_EXP"
if(code.type == image.CODABAR):
return "CODABAR"
if(code.type == image.CODE39):
return "CODE39"
if(code.type == image.PDF417):
return "PDF417"
if(code.type == image.CODE93):
return "CODE93"
if(code.type == image.CODE128):
return "CODE128"
while(True):
clock.tick()
img = csi0.snapshot()
codes = img.find_barcodes()
for code in codes:
img.draw_rectangle(code.rect)
print_args = (barcode_name(code), code.payload, (180 * code.rotation) / math.pi, code.quality, clock.fps())
print("Barcode %s, Payload \"%s\", rotation %f (degrees), quality %d, FPS %f" % print_args)
if not codes:
print("FPS %f" % clock.fps())

データマトリックス

import csi, image
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QQVGA) # M7 では QVGA も使用可能...
csi0.snapshot(frames=30)
csi0.auto_gain(False) # 画像の白飛びを防ぐため、これをオフにする必要があります...
while(True):
img = csi0.snapshot()
img.lens_corr(1.8) # 2.8mm レンズには強度1.8が適しています。
for code in img.find_datamatrices():
print(code)

{x:48, y:27, w:58, h:56, payload:"OpenMV", rotation:0.052360, rows:14, columns:14, capacity:8, padding:1}