There is a lot of information out there so I wanted to consolidate the information that I used to get it working. Hope this helps others. I'll edit the first post as needed based on feedback. This is an ongoing project so I'll update this guide as necessary to improve results.
This guide is for an ubuntu linux install of alprd (alprd runs as a linux daemon process) and the camera used was a Dahua IPC-HFW5241E-Z12E. I already had an ubuntu VM running as my Plex server so I used that. alprd should run fine alongside Plex.
You've got your camera setup in terms of location, zoom, focus. There are many posts and tips and everyone's location will be different. Once you are happy with your settings for both day and night, you are ready for this guide. Your day/night profiles should have custom exposure, shutter, gain, etc as appropriate for your environment..

0) Here are some tips that I used to dial-in my camera.


1) You will want your camera to switch between night and day modes at sunset and sunrise, respectively. You also want your pre-determined zoom and focus settings to get set after the night/day switchover. Because your camera will have a hard time auto-focusing when it's dark, we need to manually set it. This script will tell your camera to adjust its settings to what you've defined at the sunset/sunrise. Place this script on your ubuntu box, edit the settings for your environment, and setup a cron job for this to run around midnight each day. Note: the URL to get your current settings is in the script.
CameraDayNight.sh
2) Open-source alprd only supports MJPEG, so you have two options.
3) Install alprd using the guide here: OpenALPR - A How-To on Ubuntu 16.04 Desktop. This worked for me on my ubuntu 18.04 box.

4) Calibrate alprd using the guide here: Open Source — openalpr 2.8.101 documentation.
5) You should start to see some results from your ALPR server (after step 3). Might look something like this:

6) If your CPU is too high because of ALPRd, adjust your fps based on the speed of the vehicles. At 20mph, a vehicle will travel 30ft in a second. So at 10fps, you will get an image every 3ft. The higher the fps, the more processing required for alprd. Adjust it as necessary based on your CPU utilization.
7) If you have focus drift, you can use the following script. Set a cron job to run every 5-10 minutes. I found that my focus may change during the day when someone is walking their dog past the camera view.
This guide is for an ubuntu linux install of alprd (alprd runs as a linux daemon process) and the camera used was a Dahua IPC-HFW5241E-Z12E. I already had an ubuntu VM running as my Plex server so I used that. alprd should run fine alongside Plex.
You've got your camera setup in terms of location, zoom, focus. There are many posts and tips and everyone's location will be different. Once you are happy with your settings for both day and night, you are ready for this guide. Your day/night profiles should have custom exposure, shutter, gain, etc as appropriate for your environment..

0) Here are some tips that I used to dial-in my camera.
- Camera Configuration — openalpr 2.8.101 documentation
- These tips on the settings for this camera worked best for me: LPR with a pair of IPC-HFW5241E-Z12E
- more good tips here: IPC-HFW5231E-Z12 LPR from 137 feet
- location, location, location. This is the most part that contributes to successful ALPR, but of course you do the best with what you have. My spot has great light in the mornings but a glare in the afternoons. One way for me to get around this would be to install a second camera in the opposite direction (which I can't do because of a tree). Your mileage may vary.
- I may setup a 3rd manual setting during the afternoon to go in B/W mode during the afternoon glare to see if that helps.
- Make sure you can see your plates fine in the captured image/video with your eyes before you attempt to use any type of ALPR.


1) You will want your camera to switch between night and day modes at sunset and sunrise, respectively. You also want your pre-determined zoom and focus settings to get set after the night/day switchover. Because your camera will have a hard time auto-focusing when it's dark, we need to manually set it. This script will tell your camera to adjust its settings to what you've defined at the sunset/sunrise. Place this script on your ubuntu box, edit the settings for your environment, and setup a cron job for this to run around midnight each day. Note: the URL to get your current settings is in the script.
CameraDayNight.sh
Bash:
#!/bin/bash
# By reflection@IPcamtalk
# This script will switch between Day/Night modes at Sunrise/Sunset based on your location.
# Fill in the variables for your location (lat and lng)
# Fill in the variables for username and password
# Fill in the variables for your zoom and focus settings (for both day and night)
# This has been tested and works for Dahua IPC-HFW5241E-Z12E
# Edit this lat and lng based on your location
lat=38.283291
lng=-83.489213
# set your camera's IP address, username, password
cameraIP=192.168.x.x
username=userABC
password=*******
# find your desired zoom and focus using this URL (you will need to do this for day and night):
# http://<username>:<password>@<cameraIP>/cgi-bin/devVideoInput.cgi?action=getFocusStatus
# set your night zoom and focus (based on values from above)
nightzoom=1.000000
nightfocus=0.193333
# set your day zoom and focus (based on values from above)
dayzoom=1.000000
dayfocus=0.153667
# Get sunrise info
sunriseUTC=$(wget -qO- https://api.sunrise-sunset.org/json?lat=$lat\&lng=$lng\&date=today | sed "s/^.*sunrise\":\"/" | sed "s/\(^.\{1,11\}\).*/\1/" )
sunrise=$(date -d "$sunriseUTC UTC" +%I:%M%p)
# Get sunset info
sunsetUTC=$(wget -qO- https://api.sunrise-sunset.org/json?lat=$lat\&lng=$lng\&date=today | sed "s/^.*sunset\":\"/" | sed "s/\(^.\{1,11\}\).*/\1/" )
sunset=$(date -d "$sunsetUTC UTC" +%I:%M%p)
# Display sunrise and sunset values
echo "Sunrise for location $location: $sunrise"
echo "Sunset for location $location: $sunset"
# Switch to Day mode at sunrise
echo "curl -k --digest https://$username:$password@$cameraIP/cgi-bin/configManager.cgi?action=setConfig\&VideoInMode[0].Config[0]=0 ; sleep 30 ; curl -k --digest https://$username:$password@$cameraIP/cgi-bin/devVideoInput.cgi?action=adjustFocus\&focus=$dayfocus\&zoom=$dayzoom" | at -M $sunrise + 30 minutes
# Switch to Night mode at sunset
echo "curl -k --digest https://$username:$password@$cameraIP/cgi-bin/configManager.cgi?action=setConfig\&VideoInMode[0].Config[0]=1 ; sleep 30 ; curl -k --digest https://$username:$password@$cameraIP/cgi-bin/devVideoInput.cgi?action=adjustFocus\&focus=$nightfocus\&zoom=$nightzoom" | at -M $sunset - 20 minutes
2) Open-source alprd only supports MJPEG, so you have two options.
- a) you can use the substream on the Dahua IPC-HFW5241E-Z12E. Unfortunately the max resolution is D1 (703x408). This may work for you if you have a good camera location/angle. This did not work for me because my angle was about 30degrees. I can visually see the plates fine, but alprd had difficulty recognizing plates. This is one gripe I have about the 5241, its MPJEG substream max's out at D1 (even my old IP cam could do a 1080P MPJEG substream).
- b) use Blue Iris to convert the mainstream to MJPEG. This is what I did. My results were significantly better with a 720P stream than the D1 stream.
3) Install alprd using the guide here: OpenALPR - A How-To on Ubuntu 16.04 Desktop. This worked for me on my ubuntu 18.04 box.
- My existing linux box was an ubuntu 18.04 VM that I used for Plex. I have two vCPU and 8GB ram allocated to it. With Plex, the CPU is runs cool. With alprd, my CPU gets pegged at 100%. I have have iGPU passthrough set for Plex which works great, but not sure that alprd is using the iGPU.
- the MJPEG stream can be accessed via this URL: "https://<username>:<password>@<cameraIP>/cgi-bin/mjpg/video.cgi?channel=1&subtype=1". This needs to be placed in your alprd.conf file.
- The URL to stream from Blue Iris is: http://<BI-server>:<port>/mjpg/<short-camera-name>/video.mjpg. Some settings to note if you go this route. I was not able to embed the username/password into the URL, so I went to Settings->Web Server->Advanced, and added the IP address of my linux box. Also, for Encoder options, make sure you bump up quality to 100% and enable Intel QSV. I also turned off Zero frame latency. I wanted my MJPEG stream to be as close to the original H.264 stream as possible. (note: I used H.264 because there is less compression which hopefully will produce a clearer image when transcoded into MJPEG - not sure if it does but figured why not?)

4) Calibrate alprd using the guide here: Open Source — openalpr 2.8.101 documentation.
- make sure your sample image is from your the feed you are using. In other words, the D1 feed from the camera, or the 720P/1080P feed from blue iris.
- adjust your image until you are able to get the plate to be horizontal and the right aspect ratio (left-click and draw the red rectangle as your verification).
- check to your settings by running alpr manually on your test images to see if the "confidence" level is better after your calibration. If you have a good camera angle, you probably don't need to calibrate.
5) You should start to see some results from your ALPR server (after step 3). Might look something like this:

6) If your CPU is too high because of ALPRd, adjust your fps based on the speed of the vehicles. At 20mph, a vehicle will travel 30ft in a second. So at 10fps, you will get an image every 3ft. The higher the fps, the more processing required for alprd. Adjust it as necessary based on your CPU utilization.
7) If you have focus drift, you can use the following script. Set a cron job to run every 5-10 minutes. I found that my focus may change during the day when someone is walking their dog past the camera view.
Bash:
#!/bin/bash
# By reflection@IPcamtalk
# This script will adjust your focus in case there has been some drift.
# If you have different focus settings for day and night, set the dayfocus and nightfocus variables accordingly.
# Fill in the variables for your location (lat and lng)
# Fill in the variables for username and password
# Fill in the variables for your zoom and focus settings (for both day and night)
# This has been tested and works for Dahua IPC-HFW5241E-Z12E (the focus API)
# Edit lat and lng based on your location
lat=37.483844
lng=-83.439173
# set your camera's IP address, username, password
cameraIP=192.168.x.x
username=<username>
password=<password>
# find your desired zoom and focus using this URL (you will need to do this for day and night):
# http://<username>:<password>@<cameraIP>/cgi-bin/devVideoInput.cgi?action=getFocusStatus
# set your night zoom and focus
nightzoom=1.000000
nightfocus=0.186111
# set your day zoom and focus
dayzoom=1.000000
dayfocus=0.150000
# Get sunrise info
sunriseUTC=$(wget -qO- https://api.sunrise-sunset.org/json?lat=$lat\&lng=$lng\&date=today | sed "s/^.*sunrise\":\"/" | sed "s/\(^.\{1,11\}\).*/\1/" )
sunrise=$(date -d "$sunriseUTC UTC" +%k%M)
# Get sunset info
sunsetUTC=$(wget -qO- https://api.sunrise-sunset.org/json?lat=$lat\&lng=$lng\&date=today | sed "s/^.*sunset\":\"/" | sed "s/\(^.\{1,11\}\).*/\1/" )
sunset=$(date -d "$sunsetUTC UTC" +%k%M)
# Display sunrise and sunset values
echo "Sunrise for location $location: $sunrise"
echo "Sunset for location $location: $sunset"
CurrentTime=$(date +%k%M)
CurrentFocus=$(wget --no-check-certificate -qO - https://$username:$password@$cameraIP/cgi-bin/devVideoInput.cgi?action=getFocusStatus | grep "Focus=" | sed "s/status.Focus=/" | sed "s/\(^.\{1,8\}\).*/\1/" )
echo "Current focus: $CurrentFocus"
echo "Current time: $CurrentTime"
if [ $CurrentTime -gt 0 -a $CurrentTime -lt $sunrise ]; then
echo "time is before sunrise"
if [ $CurrentFocus != $nightfocus ]; then
echo "fixing night focus"
curl -k --digest https://$username:$password@$cameraIP/cgi-bin/devVideoInput.cgi?action=adjustFocus\&focus=$nightfocus\&zoom=$nightzoom
fi
elif [ $CurrentTime -gt $sunrise -a $CurrentTime -lt $sunset ]; then
echo "time is daytime"
if [ $CurrentFocus != $nightfocus ]; then
echo "fixing day focus"
curl -k --digest https://$username:$password@$cameraIP/cgi-bin/devVideoInput.cgi?action=adjustFocus\&focus=$dayfocus\&zoom=$dayzoom
fi
elif [ $CurrentTime -gt $sunset -a $CurrentTime -lt 2400 ]; then
echo "time is after sunset"
if [ $CurrentFocus != $nightfocus ]; then
echo "fixing night focus"
curl -k --digest https://$username:$password@$cameraIP/cgi-bin/devVideoInput.cgi?action=adjustFocus\&focus=$nightfocus\&zoom=$nightzoom
fi
fi
Last edited: