伙计们,我正在开发一个离线的ALPR解决方案。
到目前为止,我已经使用了运行在Ubuntu上的OpenAlpr软件。通过使用在StackOverlFlow上找到的python脚本,我能够读取ALPR的豆茎队列数据(板块号和元数据),但我需要将这些数据从豆茎队列发送到mssql数据库。有人知道如何将豆茎队列数据或JSON数据导出到数据库吗?下面的代码是针对本地主机的,如何修改它以自动将数据发布到mssql数据库?豆茎队列中的数据是JSON格式的key=value。
读写csv是我的新增功能,以查看它是否可以将json数据保存为localdisk上的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()发布于 2020-08-18 21:48:09
AFAIK没有办法直接从beanstalkd导出数据。
。
https://stackoverflow.com/questions/60109510
复制相似问题