是否有从图像中读取条形码的 R 包?

问题描述 投票:0回答:1

我正在寻找可以读取和提取扫描图像条形码数据的 R 包。 条形码采用“Interleaved 2 of 5”格式。 R 中是否有针对此任务的任何解决方案,或者我是否必须为此转移到 Python? 我宁愿坚持R.

r barcode
1个回答
0
投票

我通过从 R 脚本运行 python 脚本解决了这个问题。 我使用了 reticulate R 包,它为 Python 模块、类和函数提供了一个 R 接口。

下面给出了python脚本示例(decode_photo.py)-需要pyzbar和PIL包:

from pyzbar.pyzbar import decode
from PIL import Image
def decode_my_photo(file_name):
    result = decode(Image.open(file_name))
    decoded_items =[]
    for x in result:
        decoded_items.append(str(x.data).replace("'","").replace("b",""))
    return(decoded_items)

R脚本如下:

library(reticulate)

con <- "path_to_barcode_image.png"
use_python("C:\\Users\\MyName\\Anaconda3\\") #can be different
source_python("decode_photo.py")
decoded_value <- decode_my_photo(con)
© www.soinside.com 2019 - 2024. All rights reserved.