下面给出gn的写法,其他的构建工具,例如ndk和cmake,拿去参考改改就好了。这里还包括了libiconv的编译。
# zbar project: https://github.com/ZBar/ZBar
# libiconv project: https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
# libiconv build: https://www.codeproject.com/Articles/302012/How-to-Build-libiconv-with-Microsoft-Visual-Studio
config("zbar_config") {
include_dirs = [
"include",
"zbar",
"zbar/decoder",
"libiconv/include",
]
if (is_win) {
cflags = [
"/wd4018",
"/wd4245",
"/wd4005",
"/wd4706",
"/wd4554",
"/wd4090",
"/wd4206",
"/wd4146",
"/wd4142",
"/wd4310",
"/wd4389",
"/wd4295",
"/wd4013",
"/wd4189",
]
} else {
cflags = [
"-Wno-sign-compare",
"-Wno-unused-variable",
"-Wno-tautological-compare",
"-Wno-unused-function",
"-Wno-shift-op-parentheses",
"-Wno-logical-not-parentheses",
"-Wno-logical-op-parentheses",
"-Wno-bitwise-op-parentheses",
"-Wno-parentheses-equality",
"-Wno-incompatible-pointer-types",
"-Wno-implicit-function-declaration",
"-Wno-int-conversion",
"-Wno-unused-const-variable",
]
}
defines = [
]
}
config("public_zbar_config") {
include_dirs = [
"include",
]
}
static_library("libiconv") {
sources = [
"libiconv/iconv.c",
"libiconv/localcharset.c",
"libiconv/relocatable.c",
]
include_dirs = [
"libiconv",
"libiconv/include",
]
configs += [ ":zbar_config" ]
}
static_library("zbar") {
sources = [
"zbar/jpeg.c",
"zbar/img_scanner.c",
"zbar/decoder.c",
"zbar/image.c",
"zbar/symbol.c",
"zbar/convert.c",
"zbar/config.c",
"zbar/scanner.c",
"zbar/error.c",
"zbar/refcnt.c",
"zbar/video.c",
"zbar/video/null.c",
"zbar/decoder/code128.c",
"zbar/decoder/code39.c",
"zbar/decoder/code93.c",
"zbar/decoder/codabar.c",
"zbar/decoder/databar.c",
"zbar/decoder/ean.c",
"zbar/decoder/i25.c",
"zbar/decoder/qr_finder.c",
"zbar/decoder/pdf417.c",
"zbar/qrcode/bch15_5.c",
"zbar/qrcode/binarize.c",
"zbar/qrcode/isaac.c",
"zbar/qrcode/qrdec.c",
"zbar/qrcode/qrdectxt.c",
"zbar/qrcode/rs.c",
"zbar/qrcode/util.c",
]
configs += [ ":zbar_config" ]
public_configs = [ ":public_zbar_config" ]
deps = [
":libiconv",
"//third_party:jpeg",
]
if (is_win) {
libs = [ "winmm.lib" ]
defines = [
"WEBRTC_WIN",
]
}
}
executable("scan_image") {
sources = [ "examples/scan_image.c" ]
configs += [ ":zbar_config" ]
deps = [ ":zbar", "//third_party/libpng" ]
}
实际上不管什么类型的数据zbar都会把他转换为Y800
类型的YUV数据,也就是只有Y值的YUV数据。所以不管我们要做相机的二维码识别还是做图片(BMP\JPG)的二维码识别最终都是要把数据转换为Y800
类型。可以参考zbar的demo-scan_image.c。
我基于zbar实现了Android、iOS、Windows、Mac平台的摄像头和图片识别,都是基于此实现的,摄像头识别这块是跟平台相关的(采集),剩下的流程都是一样的。图片识别所有平台都是一样的。