Ребята В настоящее время я разрабатываю автономное решение ALPR.
До сих пор я использовал программное обеспечение OpenAlpr, работающее в Ubuntu. С помощью скрипта python, который я обнаружил в StackOverlFlow, я могу читать данные очереди beanstalk (номер пластины и метаданные) ALPR, но мне нужно отправить эти данные из очереди beanstalk в базу данных ms sql. Кто-нибудь знает, как экспортировать данные очереди beanstalk или JSON данные в базу данных? Приведенный ниже код предназначен для локального хоста. Как я могу изменить его для автоматической публикации данных в базе данных ms sql? Данные в очереди beanstalk имеют формат JSON [ключ = значение].
. Чтение и запись 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()