How to make beanstalk communicate with OpenALPR ?

2,197 views
Skip to first unread message

Marc Assin

unread,
Apr 11, 2016, 4:36:03 PM4/11/16
to OpenALPR
Hi,
I've a problem making beanstalk work with OpenALPR.
 I'm unable to troubleshoot it because I've no clear idea about how it works.

Could someone shed some light about the interaction between OpenALPR and beanstalk, especially what should be synchronized to make it work. The picture in the doc shows the commands but doesn't say much about the installation.

Thank you


Matt

unread,
Apr 11, 2016, 9:06:03 PM4/11/16
to OpenALPR
Hey Marc,

What are you trying to do?

Beanstalkd is simply used as a FIFO queue.  The OpenALPR agent places each plate result on the queue in JSON format.  Beanstalkd can have many "tubes", openALPR just uses one named "alprd"

When pulling from the queue, each result you pull off the queue is a result that represents the analysis from a still image in the video stream.

-Matt

Marc Assin

unread,
Apr 12, 2016, 4:37:09 PM4/12/16
to OpenALPR
Hi Matt,

Forgot to mention...
I've re-installed the whole stuff from scratch (again, yes!). The gitfile did run like a chief,  without any
problem, no more red lines while booting (according to fsck I had a corrupt file system)
but still "Error connecting to Beanstalk.  Result has not been saved"

Also, with the last release, there are some changes about the config file name

/etc/uv4l/uv4l-raspicam.conf            sudo service uv4l_raspicam restart
/etc/openalpr/alprd.conf        =>      /usr/local/share/openalpr/config/alprd.$
/etc/openalpr/openalpr.conf     =>      /usr/local/share/openalpr/config/openal$
/etc/default/beanstalkd         =>      /etc/init.d/beanstalkd on
/etc/init.d/beanstalkd


> What are you trying to do?
Well, you guessed, it looks like I've put both feet in same shoe :-)

> Beanstalkd is simply used as a FIFO queue.  The OpenALPR agent places each plate result on the queue in 
JSON format. 
OK, so far, so good

> Beanstalkd can have many "tubes", openALPR just uses one named "alprd"
When pulling from the queue, each result you pull off the queue is a result that represents the analysis from 
a still image in the video stream.
OK. Although I understand the principle, rather simple, I can't figure out the implementations details.

If I recall my experience (from a previous life): in order to communicate, both applications must share a 
common interface or a common set of parameters. In this particular instance, I guess the talker & listener 
have to share the same port. The doc and some examples mention port 11300 and/or 14711
I've edited the conf files and your script to use my IP instead of 'localhost' and port 14711.
Maybe something wrong ?

Thank you for taking the time and trouble to help a newbee.

Worth mentionning, things have never run so smooth since the last re-install from scratvh. I think I'm very 
close to the solution, but I can't proceed any further as long as I haven't cured a couple error messages.

I've attached the config files for reference.
Back to your question:
When I start alpr like:
alprd -l 1 --config /etc/openalpr -f
and run your script, I get

INFO - Running OpenALPR daemon in the foreground.
INFO - Using: /etc/openalpr/alprd.conf for daemon configuration
Missing config value for company_id
INFO - Using: /home/pi/Pictures/ for storing valid plate images
INFO - country: eu -- config file: /etc/openalpr/openalpr.conf
INFO - Stream 1: webcam
INFO - Starting camera 1
INFO - Video stream connecting...
/dev/video0 does not support memory mapping
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
INFO - Video stream connected
DEBUG - Writing plate 5721MJ32 (beausoleil-cam1-1460405356650) to queue.
WARN - Error connecting to Beanstalk.  Result has not been saved.
DEBUG - Writing plate 5721MJ32 (beausoleil-cam1-1460405357449) to queue.
WARN - Error connecting to Beanstalk.  Result has not been saved.
DEBUG - Writing plate 5721MJ32 (beausoleil-cam1-1460405358248) to queue.

I thought clearing the errors would be the best way to go, before going on, or should I just "forget" it ? 
with the risk of being caught later.

/etc/openalpr/alprd.conf
; This configuration file overrides the default values specified
; in /usr/local/share/openalpr/config/alprd.defaults.conf
[daemon]
country = eu
site_id = beausoleil
stream = webcam
topn = 1
store_plates = 1
store_plates_location = /home/pi/Pictures/
; upload_data = 0
; upload_address = http://localhost:9000/push/

/usr/local/share/openalpr/config/alprd.defaults.conf
[daemon]

; country determines the training dataset used for recognizing plates.
; Valid values are: us, eu, au, auwide, gb, kr, mx, sg
country = us

; text name identifier for this location
;   site_id = your-unique-sitename

; Declare each stream on a separate line
; each unique stream should be defined as stream = [url]

; Example stream config:
;   stream = webcam

; topn is the number of possible plate character variations to report
topn = 10

; Determines whether images that contain plates should be stored to disk
store_plates = 0
store_plates_location = /var/lib/openalpr/plateimages/

; upload address is the destination to POST to
upload_data = 0

/etc/openalpr/openalpr.conf
; This configuration file overrides the default values specified
; in /usr/local/share/openalpr/config/openalpr.defaults.conf

/usr/local/share/openalpr/config/openalpr.defaults.conf
; Specify the path to the runtime data directory
runtime_dir = /usr/local/share/openalpr/runtime_data

ocr_img_size_percent = 1.33333333
state_id_img_size_percent = 2.0

; Calibrating your camera improves detection accuracy in cases where vehicle pl$
; Use the openalpr-utils-calibrate utility to calibrate your fixed camera to ad$
; Once done, update the prewarp config with the values obtained from the tool
prewarp =

; detection will ignore plates that are too large.  This is a good efficiency t$
; plates are going to be a fixed distance away from the camera (e.g., you will $
; up the entire image
max_plate_width_percent = 100
max_plate_height_percent = 100

; detection_iteration_increase is the percentage that the LBP frame increases e$
; It must be greater than 1.0.  A value of 1.01 means increase by 1%, 1.10 incr$
; So a 1% increase would be ~10x slower than 10% to process, but it has a highe$
; directly on the plate and getting a strong detection
detection_iteration_increase = 1.1

; The minimum detection strength determines how sure the detection algorithm mu$
; a plate region exists.  Technically this corresponds to LBP nearest neighbors$
; are clustered around the same area).  For example, 2 = very lenient, 9 = very$
detection_strictness = 3
; The detection doesn't necessarily need an extremely high resolution image in $
; Using a smaller input image should still find the plates and will do it faster
; Tweaking the max_detection_input values will resize the input image if it is $
; max_detection_input_width/height are specified in pixels
max_detection_input_width = 1280
max_detection_input_height = 720

; detector is the technique used to find license plate regions in an image.  Va$
; lbpcpu    - default LBP-based detector uses the system CPU
; lbpgpu    - LBP-based detector that uses Nvidia GPU to increase recognition s$
; lbpopencl - LBP-based detector that uses OpenCL GPU to increase recognition s$
; morphcpu  - Experimental detector that detects white rectangles in an image. $
detector = lbpcpu

; If set to true, all results must match a postprocess text pattern if a patter$
; If not, the result is disqualified.
must_match_pattern = 0

; Bypasses plate detection.  If this is set to 1, the library assumes that each$
skip_detection = 0
; Specifies the full path to an image file that constrains the detection area. $
; will be analyzed.  The mask image must match the resolution of your image to $
; Black areas will be ignored, white areas will be searched.  An empty value me$
detection_mask_image =

; OpenALPR can scan the same image multiple times with different randomization.$
; 1 may increase accuracy, but will increase processing time linearly (e.g., an$
analysis_count = 1
; OpenALPR detects high-contrast plate crops and uses an alternative edge detec$
; would classify  ALL images as high-contrast, setting it to 1.0 would classify$
contrast_detection_threshold = 0.3

max_plate_angle_degrees = 15

ocr_min_font_point = 6

; Minimum OCR confidence percent to consider.
postprocess_min_confidence = 65
; Any OCR character lower than this will also add an equally likely
; chance that the character is incorrect and will be skipped.  Value is a confi$
postprocess_confidence_skip_level = 80

debug_general         = 0
debug_timing          = 0
debug_detector        = 0
debug_prewarp         = 0
debug_state_id        = 0


/etc/default/beanstalkd
## Defaults for the beanstalkd init script, /etc/init.d/beanstalkd on
## Debian systems.

BEANSTALKD_LISTEN_ADDR=10.0.1.184
BEANSTALKD_LISTEN_PORT=14711

# You can use BEANSTALKD_EXTRA to pass additional options.
# See beanstalkd(1) for a list of the available options.
# Uncomment the following line for persistent job storage.
#BEANSTALKD_EXTRA="-b /var/lib/beanstalkd"


/etc/init.d/beanstalkd 
extract
# Default options, these can be overriden by the information
# at /etc/default/$NAME
BEANSTALKD_LISTEN_ADDR="10.0.1.184"
BEANSTALKD_LISTEN_PORT=14711
BEANSTALKD_EXTRA=""



Marc Assin

unread,
Apr 13, 2016, 3:41:17 AM4/13/16
to OpenALPR
and the output fromyour script

pi@alpr:~ $ python bin/python/drain_openalpr_queue.py
Traceback (most recent call last):
  File "bin/python/drain_openalpr_queue.py", line 8, in <module>
    my_bean = beanstalkc.Connection(host='10.0.1.184', port=14711)
  File "/usr/local/lib/python2.7/dist-packages/beanstalkc.py", line 59, in __init__
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/beanstalkc.py", line 65, in connect
    SocketError.wrap(self._socket.connect, (self.host, self.port))
  File "/usr/local/lib/python2.7/dist-packages/beanstalkc.py", line 43, in wrap
    raise SocketError(err)
beanstalkc.SocketError: [Errno 111] Connection refused

Which package are you using for the beanstalk-client ? 

Matt

unread,
Apr 15, 2016, 9:39:30 AM4/15/16
to OpenALPR
I think the issue you're having is this one:
WARN - Error connecting to Beanstalk.  Result has not been saved.

OpenALPR is trying to connect to Beanstalkd to push the results, but it is not working.  What is the output from the following commands:
ps -Af | grep beanstalk
netstat -lnp | grep 11300
which beanstalkd

Marc Assin

unread,
Apr 15, 2016, 2:57:38 PM4/15/16
to OpenALPR


Hi Matt,

I just made the first turn of the wheel. I'm not going to make any comment until I'm sure about what is going on here. 
I've had the pleasure to see

alprd --config /etc/openalpr -f 
----------------------------------
INFO - Video stream connecting...
/dev/video0 does not support memory mapping
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
INFO - Video stream connected
DEBUG - Writing plate 5721J32 (beausoleil-cam1-1460745204072) to queue. <===============
DEBUG - put job id: 1
DEBUG - Writing plate 5721J32 (beausoleil-cam1-1460745204992) to queue.

output from your script
------------------------
Found a plate!
This is a plate result <===================
Found a plate!
This is a plate result
Found a plate!
This is a plate result
No plates available right now, waiting...
No plates available right now, waiting...


I've still some work to do, but seeing the end   :-)

---------------------------------------------------

> OpenALPR is trying to connect to Beanstalkd to push the results, but it is not working.
Yes, indeed

> What is the output from the following commands:

pi@alpr:~ $ ps -Af | grep beanstalk
pi        2854  2389  0 20:31 pts/0    00:00:00 beanstalkd -l 127.0.0.1 -p 11300
pi        3053  3009  0 20:40 pts/4    00:00:00 grep --color=auto beanstalk


pi@alpr:~ $ sudo netstat -lnp | grep 11300
tcp        0      0 127.0.0.1:11300         0.0.0.0:*               LISTEN      2854/beanstalkd


> which beanstalkd

RASPBIAN JESSIE
Full desktop image based on Debian Jessie

Version: 2016-03-18-raspbian-jessie 
Release date: 18 March 2016
Kernel version: 4.1
Release notes: Link
Download: ZIP

Python: 2.7.9
PyYAML x
PIP: 8.0.3
alprd: 2.2.4
beanstalkd: 1.10


Matt

unread,
Apr 17, 2016, 8:45:47 AM4/17/16
to OpenALPR
Cool.  It looks like it's working.  alprd pushes to the queue, and that script is pulling from it.  What did you need to change to make it work?  I'm guessing BEANSTALKD_LISTEN_ADDR and BEANSTALKD_LISTEN_PORT were changed?

Marc Assin

unread,
Apr 17, 2016, 11:11:39 AM4/17/16
to OpenALPR
Hi Matt,

 What did you need to change to make it work?
Mmm, I'm waiting an expert's advice before publishing
 
 I'm guessing BEANSTALKD_LISTEN_ADDR and BEANSTALKD_LISTEN_PORT were changed?
Good guess, indeed :-)
I've done that a hundred times :-(
It looks like it's not a beanstalk or alpr issue. I stumbled over a network problem

Marc Assin

unread,
Apr 18, 2016, 6:11:09 PM4/18/16
to OpenALPR
Le dimanche 17 avril 2016 14:45:47 UTC+2, 
Matt a écrit : 
What did you need to change to make it work?  I'm guessing BEANSTALKD_LISTEN_ADDR and BEANSTALKD_LISTEN_PORT were changed?

Well, I've my own domain on the internal LAN, so my FQDN is something like: alpr.xyz.local
All name resolution towards alpr work fine, short or FQDN
All name resolution from alpr towards any PC on the LAN work only in the short form. FQDN fail
The expert was quick to trace the problem to the avahi.conf

/etc/avahi/avahi-daemon.conf
----------------------------
server section
add domain local
Reply all
Reply to author
Forward
0 new messages