0

伙计们,我目前正在开发离线 ALPR 解决方案。

到目前为止,我已经使用了在 Ubuntu 上运行的 OpenAlpr 软件。通过使用我在 StackOverlFlow 上找到的 python 脚本,我能够读取 ALPR 的 beanstalk 队列数据(车牌号和元数据),但我需要将此数据从 beanstalk 队列发送到 mssql 数据库。有谁知道如何将 beanstalk 队列数据或 JSON 数据导出到数据库?下面的代码是针对本地主机的,我如何修改它以自动将数据发布到 mssql 数据库?beanstalk 队列中的数据是 JSON 格式 [key=value]。

读写 csv 是我添加的,看看它是否可以将 json 数据保存为本地磁盘上的 csv

import beanstalkc
import json
from pprint import pprint

beanstalk = beanstalkc.Connection(host='localhost', port=11300)
TUBE_NAME='alprd'
text_file = open('output.csv', 'w')

# For diagnostics, print out a list of all the tubes available in Beanstalk.
print beanstalk.tubes()

# For diagnostics, print the number of items on the current alprd queue.
try:
    pprint(beanstalk.stats_tube(TUBE_NAME))
except beanstalkc.CommandFailed:
    print "Tube doesn't exist"

# Watch the "alprd" tube; this is where the plate data is.
beanstalk.watch(TUBE_NAME)


while True:

    # Wait for a second to get a job. If there is a job, process it and delete it from the queue.
    # If not, return to sleep.
    job = beanstalk.reserve(timeout=5000)
    if job is None:
        print "No plates yet"
    else:
        plates_info = json.loads(job.body)
    # Do something with this data (e.g., match a list, open a gate, etc.).
    # if 'data_type' not in plates_info:
        # print "This shouldn't be here... all OpenALPR data should have a data_type"
    # if plates_info['data_type'] == 'alpr_results':
        # print "Found an individual plate result!"
    if plates_info['data_type'] == 'alpr_group':
        print "Found a group result!"
        print '\tBest plate: {} ({:.2f}% confidence)'.format(
            plates_info['candidates'][0]['plate'], 
            plates_info['candidates'][0]['confidence'])
        make_model = plates_info['vehicle']['make_model'][0]['name']
        print '\tVehicle information: {} {} {}'.format(
            plates_info['vehicle']['year'][0]['name'],
            plates_info['vehicle']['color'][0]['name'],
            ' '.join([word.capitalize() for word in make_model.split('_')]))
    elif plates_info['data_type'] == 'heartbeat':
        print "Received a heartbeat"
        text_file.write('Best plate')
    # Delete the job from the queue when it is processed.

job.delete()
text_file.close()
4

1 回答 1

0

AFAIK 无法直接从 beanstalkd 导出数据。

  • 你所拥有的东西是有道理的,那就是将数据从管中流式传输到平面文件中或直接插入到数据库中
  • 鉴于可以生成 IOPS beanstalkd,它可能仍然是一个合理的解决方案(取决于您期望的性能)

也尝试询问https://groups.google.com/forum/#!forum/beanstalk-talk

于 2020-08-18T21:48:09.933 回答