Lecture de plaque d’immatriculation
Pour faire suite à l’article du drone, j’ai suivi l’installation d’ALPR grace à OpenALPR (Automated License Plate Recognition)
Il faut :
Une raspberry pi avec jessie,
Une camera
Le plus simple également est de passer par VNC viewer en activant le VNC sur l’écran de configuration de la raspberry.
j’ai utilisé la procédure “Easy Way” qui fonctionne à partir de ce site
https://github.com/openalpr/openalpr/wiki/Compilation-instructions-(Ubuntu-Linux)
la façon “Easiest Way” ne marche pas dans mon cas (dommage).
les lignes de commande (ça prend bien 20 minutes … en particulier après le “make”)
<span class="pl-c"># Install prerequisites</span>
sudo apt-get install libopencv-dev libtesseract-dev git cmake build-essential libleptonica-dev
sudo apt-get install liblog4cplus-dev libcurl3-dev
<span class="pl-c"># If using the daemon, install beanstalkd</span>
sudo apt-get install beanstalkd
<span class="pl-c"># Clone the latest code from GitHub</span>
git clone https://github.com/openalpr/openalpr.git
<span class="pl-c"># Setup the build directory</span>
<span class="pl-c1">cd</span> openalpr/src
mkdir build
<span class="pl-c1">cd</span> build
<span class="pl-c"># setup the compile environment</span>
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc ..
<span class="pl-c"># compile the library</span>
make
<span class="pl-c"># Install the binaries/libraries to your local system (prefix is /usr)</span>
sudo make install
<span class="pl-c"># Test the library</span>
wget http://plates.openalpr.com/h786poj.jpg -O lp.jpg
alpr lp.jpg<code></code>

Sur cette image, j’obtiens
plate0: 10 results
- EA7THE confidence: 91.0578
- EA7TBE confidence: 84.133
- EA7T8E confidence: 83.0083
- EA7TRE confidence: 82.7869
- EA7TE confidence: 82.5961
- EA7TME confidence: 80.2908
- EA7TH6 confidence: 77.0045
- EA7THB confidence: 75.5779
- EA7TH confidence: 74.6576
- EA7TB6 confidence: 70.0797
ici, j’ai trouvé un code de détection https://www.gadgetdaily.xyz/raspberry-pi-motion-detection/
xxx
Attention au copier coller il faut modifier les guillemets de bmp et après file sinon, il y a une erreur
xxx
Ensuite, exécuter la commande :
sudo apt-get install python-picamera python-imaging-tk
import io
import os
import picamera
import time
from datetime import datetime
from PIL import Image
camera = picamera.PiCamera()
difference = 20
pixels = 100
width = 1280
height = 960
def compare():
camera.resolution = (100, 75)
stream = io.BytesIO()
camera.capture(stream, format = ‘bmp’)
stream.seek(0)
im = Image.open(stream)
buffer = im.load()
stream.close()
return im, buffer
def newimage(width, height):
time = datetime.now()
filename = “motion-%04d%02d%02d-%02d%02d%02d.jpg” % (time.year, time.month, time.day, time.hour, time.minute, time.second)
camera.resolution = (width, height)
camera.capture(filename)
print “Captured %s” % filename
image1, buffer1 = compare()
timestamp = time.time()
while (True):
image2, buffer2 = compare()
changedpixels = 0
for x in xrange(0, 100):
for y in xrange(0, 75):
pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
if pixdiff > difference:
changedpixels += 1
if changedpixels > pixels:
timestamp = time.time()
newimage(width, height)
image1 = image2
buffer1 = buffer2
ça fonctionne bien et créé plein d’image à chaque détection de mouvement.
Reste plus qu’à relier les deux programmes …
voila ce que ça donne et ça marche
#ne marche qu'en python 2
#programme qui integre alpr et motion detection
import io
import os
import picamera
import time
from datetime import datetime
from PIL import Image
from openalpr import Alpr #vient d'alpr
camera = picamera.PiCamera()
difference = 20
pixels = 100
width = 1280
height = 960
def compare():
camera.resolution = (100, 75)
stream = io.BytesIO()
camera.capture(stream, format = 'bmp')
stream.seek(0)
im = Image.open(stream)
buffer = im.load()
stream.close()
return im, buffer
def newimage(width, height):
time = datetime.now()
filename = "motion-%04d%02d%02d-%02d%02d%02d.jpg" % (time.year, time.month, time.day, time.hour, time.minute, time.second)
camera.resolution = (width, height)
camera.capture(filename)
print "Captured %s" % filename
#c'est ici qu'on intègre le code alpr
alpr = Alpr("eu", "/home/pi/openalpr/config/openalpr.conf.defaults", "/home/pi/openalpr/runtime_data")
if not alpr.is_loaded():
print("Error loading OpenALPR")
exit() #sys.exit(1)
alpr.set_top_n(5)
#alpr.set_default_region("md")
results = alpr.recognize_file(filename)
i = 0
for plate in results['results']:
i += 1
print("Plate #%d" % i)
print(" %12s %12s" % ("Plate", "Confidence"))
for candidate in plate['candidates']:
prefix = "-"
if candidate['matches_template']:
prefix = "*"
print(" %s %12s%12f" % (prefix, candidate['plate'], candidate['confidence']))
# Call when completely done to release memory
alpr.unload()
#fin de l'insertion
image1, buffer1 = compare()
imestamp = time.time()
while (True):
image2, buffer2 = compare()
changedpixels = 0
for x in xrange(0, 100):
for y in xrange(0, 75):
pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
if pixdiff > difference:
changedpixels += 1
if changedpixels > pixels:
timestamp = time.time()
newimage(width, height)
image1 = image2
buffer1 = buffer2
Voila le résultat en vidéo : voir la vidéo
ça fonctionne bien lorsque l’image est bonne et moins si la voiture se déplace.
Du coup, j’ai inverti dans une caméra un peu plus robuste pour voir si cela était plus performant.
Voila j’ai acheté la v2 (15euros sur mon site chinois)
Je vais d’abord tester l’image
du coup, pour ça, j’installe de quoi faire de la vidéo
raspivid -o video.h264 -t 10000
<code class=" language-bash"><span class="token function">raspivid -o video.h264 -t 10000</span></code> permet de prendre 10s de vidéo
Lire d'autres posts
Pour faire suite à l’article du drone, j’ai suivi l’installation d’ALPR grace à OpenALPR (Automated License Plate Recognition)
Il faut :
Une raspberry pi avec jessie,
Une camera
Le plus simple également est de passer par VNC viewer en activant le VNC sur l’écran de configuration de la raspberry.
j’ai utilisé la procédure “Easy Way” qui fonctionne à partir de ce site
https://github.com/openalpr/openalpr/wiki/Compilation-instructions-(Ubuntu-Linux)
la façon “Easiest Way” ne marche pas dans mon cas (dommage).
les lignes de commande (ça prend bien 20 minutes … en particulier après le “make”)
<span class="pl-c"># Install prerequisites</span>
sudo apt-get install libopencv-dev libtesseract-dev git cmake build-essential libleptonica-dev
sudo apt-get install liblog4cplus-dev libcurl3-dev
<span class="pl-c"># If using the daemon, install beanstalkd</span>
sudo apt-get install beanstalkd
<span class="pl-c"># Clone the latest code from GitHub</span>
git clone https://github.com/openalpr/openalpr.git
<span class="pl-c"># Setup the build directory</span>
<span class="pl-c1">cd</span> openalpr/src
mkdir build
<span class="pl-c1">cd</span> build
<span class="pl-c"># setup the compile environment</span>
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc ..
<span class="pl-c"># compile the library</span>
make
<span class="pl-c"># Install the binaries/libraries to your local system (prefix is /usr)</span>
sudo make install
<span class="pl-c"># Test the library</span>
wget http://plates.openalpr.com/h786poj.jpg -O lp.jpg
alpr lp.jpg<code></code>

Sur cette image, j’obtiens plate0: 10 results
- EA7THE confidence: 91.0578
- EA7TBE confidence: 84.133
- EA7T8E confidence: 83.0083
- EA7TRE confidence: 82.7869
- EA7TE confidence: 82.5961
- EA7TME confidence: 80.2908
- EA7TH6 confidence: 77.0045
- EA7THB confidence: 75.5779
- EA7TH confidence: 74.6576
- EA7TB6 confidence: 70.0797
ici, j’ai trouvé un code de détection https://www.gadgetdaily.xyz/raspberry-pi-motion-detection/
xxx
Attention au copier coller il faut modifier les guillemets de bmp et après file sinon, il y a une erreur
xxx
Ensuite, exécuter la commande :
sudo apt-get install python-picamera python-imaging-tk
import io
import os
import picamera
import time
from datetime import datetime
from PIL import Image
camera = picamera.PiCamera()
difference = 20
pixels = 100
width = 1280
height = 960
def compare():
camera.resolution = (100, 75)
stream = io.BytesIO()
camera.capture(stream, format = ‘bmp’)
stream.seek(0)
im = Image.open(stream)
buffer = im.load()
stream.close()
return im, buffer
def newimage(width, height):
time = datetime.now()
filename = “motion-%04d%02d%02d-%02d%02d%02d.jpg” % (time.year, time.month, time.day, time.hour, time.minute, time.second)
camera.resolution = (width, height)
camera.capture(filename)
print “Captured %s” % filename
image1, buffer1 = compare()
timestamp = time.time()
while (True):
image2, buffer2 = compare()
changedpixels = 0
for x in xrange(0, 100):
for y in xrange(0, 75):
pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
if pixdiff > difference:
changedpixels += 1
if changedpixels > pixels:
timestamp = time.time()
newimage(width, height)
image1 = image2
buffer1 = buffer2
ça fonctionne bien et créé plein d’image à chaque détection de mouvement.
Reste plus qu’à relier les deux programmes …
voila ce que ça donne et ça marche
#ne marche qu'en python 2
#programme qui integre alpr et motion detection
import io
import os
import picamera
import time
from datetime import datetime
from PIL import Image
from openalpr import Alpr #vient d'alpr
camera = picamera.PiCamera()
difference = 20
pixels = 100
width = 1280
height = 960
def compare():
camera.resolution = (100, 75)
stream = io.BytesIO()
camera.capture(stream, format = 'bmp')
stream.seek(0)
im = Image.open(stream)
buffer = im.load()
stream.close()
return im, buffer
def newimage(width, height):
time = datetime.now()
filename = "motion-%04d%02d%02d-%02d%02d%02d.jpg" % (time.year, time.month, time.day, time.hour, time.minute, time.second)
camera.resolution = (width, height)
camera.capture(filename)
print "Captured %s" % filename
#c'est ici qu'on intègre le code alpr
alpr = Alpr("eu", "/home/pi/openalpr/config/openalpr.conf.defaults", "/home/pi/openalpr/runtime_data")
if not alpr.is_loaded():
print("Error loading OpenALPR")
exit() #sys.exit(1)
alpr.set_top_n(5)
#alpr.set_default_region("md")
results = alpr.recognize_file(filename)
i = 0
for plate in results['results']:
i += 1
print("Plate #%d" % i)
print(" %12s %12s" % ("Plate", "Confidence"))
for candidate in plate['candidates']:
prefix = "-"
if candidate['matches_template']:
prefix = "*"
print(" %s %12s%12f" % (prefix, candidate['plate'], candidate['confidence']))
# Call when completely done to release memory
alpr.unload()
#fin de l'insertion
image1, buffer1 = compare()
imestamp = time.time()
while (True):
image2, buffer2 = compare()
changedpixels = 0
for x in xrange(0, 100):
for y in xrange(0, 75):
pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
if pixdiff > difference:
changedpixels += 1
if changedpixels > pixels:
timestamp = time.time()
newimage(width, height)
image1 = image2
buffer1 = buffer2
Voila le résultat en vidéo : voir la vidéo
ça fonctionne bien lorsque l’image est bonne et moins si la voiture se déplace.
Du coup, j’ai inverti dans une caméra un peu plus robuste pour voir si cela était plus performant.
Voila j’ai acheté la v2 (15euros sur mon site chinois)
Je vais d’abord tester l’image
du coup, pour ça, j’installe de quoi faire de la vidéo
raspivid -o video.h264 -t 10000
<code class=" language-bash"><span class="token function">raspivid -o video.h264 -t 10000</span></code> permet de prendre 10s de vidéo