以下圖片可右擊查看放大后查看左下角打印數據
二維碼
1 import sensor, image 2 3 sensor.reset() 4 sensor.set_pixformat(sensor.RGB565) 5 sensor.set_framesize(sensor.QQVGA) # can be QVGA on M7... 6 sensor.skip_frames(30) 7 sensor.set_auto_gain(False) # must turn this off to prevent image washout... 8 while(True): 9 img = sensor.snapshot() 10 img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens. 11 for code in img.find_qrcodes(): 12 print(code)
uart = UART(3, 9600)
for code in img.find_qrcodes():
message = code.payload()
uart.write(message)
print(code)
image.
find_qrcodes
([roi])
查找 roi
內的所有二維碼並返回一個 image.qrcode
對象的列表。 請參考 image.qrcode
對象以獲取更多信息。
為使這一方法成功運行,圖像上二維碼需比較平展。因為openmv的鏡頭為魚眼鏡頭可以通過物理鏡頭消除畸變影響,也可以通過使用 sensor.set_windowing
函數在鏡頭中心放大、image.lens_corr
函數來消解鏡頭的桶形畸變或通過更換視野較為狹小的鏡頭, 您可得到一個不受鏡頭畸變影響的更為平展的二維碼。有些機器視覺鏡頭不會造成桶形失真,但是其造價遠比OpenMV提供的標准鏡片高,這種鏡頭為無畸變鏡頭。
roi
是一個用以復制的矩形的感興趣區域(x, y, w, h)。如果未指定,ROI即整幅圖像的圖像矩形。 操作范圍僅限於 roi
區域內的像素。
不支持壓縮圖像和bayer圖像。
此方法在OpenMV Cam M4 上不可用。
-
qrcode.
corners
() -
返回一個由該對象的四個角組成的四個元組(x,y)的列表。四個角通常是按照從左上角開始沿順時針順序返回的。
-
qrcode.
rect
() -
返回一個矩形元組(x, y, w, h),用於如二維碼的邊界框的
image.draw_rectangle
等其他的image
方法。
-
qrcode.
x
() -
返回二維碼的邊界框的x坐標(int)。
您也可以通過索引
[0]
取得這個值。
-
qrcode.
y
() -
返回二維碼的邊界框的y坐標(int)。
您也可以通過索引
[1]
取得這個值。
-
qrcode.
w
() -
返回二維碼的邊界框的w坐標(int)。
您也可以通過索引
[2]
取得這個值。
-
qrcode.
h
() -
返回二維碼的邊界框的h坐標(int)。
您也可以通過索引
[3]
取得這個值。
-
qrcode.
payload
() -
返回二維碼有效載荷的字符串,例如URL 。該示例中的內容為openmv
您也可以通過索引
[4]
取得這個值。
-
qrcode.
version
() -
返回二維碼的版本號(int)。
您也可以通過索引
[5]
取得這個值。
-
qrcode.
ecc_level
() -
返回二維碼的ECC水平(int)。
您也可以通過索引
[6]
取得這個值。
-
qrcode.
mask
() -
返回二維碼的掩碼(int)。
您也可以通過索引
[7]
取得這個值。
-
qrcode.
data_type
() -
返回二維碼的數據類型。
您也可以通過索引
[8]
取得這個值。
-
qrcode.
eci
() -
返回二維碼的ECI。ECI儲存了QR碼中存儲數據字節的編碼。若您想要處理包含超過標准ASCII文本的二維碼,您需要查看這一數值。
您也可以通過索引
[9]
取得這個值。
-
qrcode.
is_numeric
() -
若二維碼的數據類型為數字式,則返回True。
-
qrcode.
is_alphanumeric
() -
若二維碼的數據類型為文字數字式,則返回True。
-
qrcode.
is_binary
() -
若二維碼的數據類型為二進制式,則返回True。如果您認真處理所有類型的文本,則需要檢查eci是否為True,以確定數據的文本編碼。通常它只是標准的ASCII,但是它也可能是有兩個字節字符的UTF8。
-
qrcode.
is_kanji
() -
若二維碼的數據類型為日本漢字,則返回True。設置為True后,您就需要自行解碼字符串,因為日本漢字符號每個字符是10位,而MicroPython不支持解析這類文本
條形碼
1 import sensor, image, time, math 2 3 sensor.reset() 4 sensor.set_pixformat(sensor.GRAYSCALE) 5 sensor.set_framesize(sensor.VGA) # High Res! 6 sensor.set_windowing((640, 80)) # V Res of 80 == less work (40 for 2X the speed). 7 sensor.skip_frames(30) 8 sensor.set_auto_gain(False) # must turn this off to prevent image washout... 9 sensor.set_auto_whitebal(False) # must turn this off to prevent image washout... 10 clock = time.clock() 11 12 # Barcode detection can run at the full 640x480 resolution of your OpenMV Cam's 13 # OV7725 camera module. Barcode detection will also work in RGB565 mode but at 14 # a lower resolution. That said, barcode detection requires a higher resolution 15 # to work well so it should always be run at 640x480 in grayscale... 16 17 def barcode_name(code): 18 if(code.type() == image.EAN2): 19 return "EAN2" 20 if(code.type() == image.EAN5): 21 return "EAN5" 22 if(code.type() == image.EAN8): 23 return "EAN8" 24 if(code.type() == image.UPCE): 25 return "UPCE" 26 if(code.type() == image.ISBN10): 27 return "ISBN10" 28 if(code.type() == image.UPCA): 29 return "UPCA" 30 if(code.type() == image.EAN13): 31 return "EAN13" 32 if(code.type() == image.ISBN13): 33 return "ISBN13" 34 if(code.type() == image.I25): 35 return "I25" 36 if(code.type() == image.DATABAR): 37 return "DATABAR" 38 if(code.type() == image.DATABAR_EXP): 39 return "DATABAR_EXP" 40 if(code.type() == image.CODABAR): 41 return "CODABAR" 42 if(code.type() == image.CODE39): 43 return "CODE39" 44 if(code.type() == image.PDF417): 45 return "PDF417" 46 if(code.type() == image.CODE93): 47 return "CODE93" 48 if(code.type() == image.CODE128): 49 return "CODE128" 50 51 while(True): 52 clock.tick() 53 img = sensor.snapshot() 54 codes = img.find_barcodes() 55 for code in codes: 56 img.draw_rectangle(code.rect()) 57 print_args = (barcode_name(code), code.payload(), (180 * code.rotation()) / math.pi, code.quality(), clock.fps()) 58 print("Barcode %s, Payload \"%s\", rotation %f (degrees), quality %d, FPS %f" % print_args) 59 if not codes: 60 print("FPS %f" % clock.fps())
-
barcode.
corners
() -
返回一個由該對象的四個角組成的四個元組(x,y)的列表。四個角通常是按照從左上角開始沿順時針順序返回的。
-
barcode.
rect
() -
返回一個矩形元組(x, y, w, h),用於如數據矩陣的邊界框的
image.draw_rectangle
等其他的image
方法。
-
barcode.
x
() -
返回條形碼的邊界框的x坐標(int)。
您也可以通過索引
[0]
取得這個值。
-
barcode.
y
() -
返回條形碼的邊界框的y坐標(int)。
您也可以通過索引
[1]
取得這個值。
-
barcode.
w
() -
返回條形碼的邊界框的w寬度(int)。
您也可以通過索引
[2]
取得這個值。
-
barcode.
h
() -
返回條形碼的邊界框的h高度(int)。
您也可以通過索引
[3]
取得這個值。
-
barcode.
payload
() -
返回條形碼的有效載荷的字符串。例:數量。
您也可以通過索引
[4]
取得這個值。
-
barcode.
type
() -
返回條形碼的列舉類型 (int)。
您也可以通過索引
[5]
取得這個值。- image.EAN2
- image.EAN5
- image.EAN8
- image.UPCE
- image.ISBN10
- image.UPCA
- image.EAN13
- image.ISBN13
- image.I25
- image.DATABAR
- image.DATABAR_EXP
- image.CODABAR
- image.CODE39
- image.PDF417 - 未來啟用 (e.g. 現在還不能正常使用).
- image.CODE93
- image.CODE128
-
barcode.
rotation
() -
返回以弧度計的條形碼的旋度(浮點數)。
您也可以通過索引
[6]
取得這個值。
-
barcode.
quality
() -
返回條形碼在圖像中被檢測到的次數(int)。
掃描條形碼時,每一條新的掃描線都能解碼相同的條形碼。每次進行這一過程,條形碼的值都會隨之增加。
您也可以通過索引
[7]
取得這個值。