OpenAlpr with webcam on Pi3

Last time I made an installation on Pi with 16GB microSD card on Pi3.
it's tested with a stored jpg...result is good...

Now I wish to make it works with SUB webcam I have on hand, which is a Logitech..
after plug in:
it's detected, and works as a USB Class Video as ttyvideo0


INSTALL FSWEBCAM

First, install the fswebcam package:
sudo apt-get install fswebcam

then test it:

fswebcam image.jpg




I got a black screen....something need to be done...

not sure what error is this: GD Error: gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file

I found a reason here: https://forum.arduino.cc/index.php?topic=253571.0
the problem was the frames.

The camera gives black because it cant take a picture with one frame.

You have to:
1)skip the first frames with the -S 10
2)or take the pictures with more frames -F 10 (range 1-255) 255 is slow
3) or give more power to camera (usb hub)

so this can give a normal picture.   XD
Code: [Select]
fswebcam  -i 0 -d v4l2:/dev/video0  --jpeg 95  --save test.jpg -S 20 -r 640x480




Now it's time to find a plate and test....

this is a python written by luka...very nice one...
https://github.com/lukagabric/PyALPR/blob/master/PyALPR.py

Is Taiwanese car plate works? I went on the steet and took few photos with my mobile and send to Pi3...
there are 2 kind of car plates, in Taiwan, seems both works fine with us option(which is default)



My current Pi3 is still on table, can't be took out door, so, I display the pic I have on PC, and use

 fswebcam  -i 0 -d v4l2:/dev/video0  --jpeg 95  --save test.jpg -S 20 -r 640x480

to get a pic as test.jpg
the run alpr test.jpg

the result is good...

this is what on the monitor

this is what the web cam got...



To get things work on python, I refer to this:


he made a script for python using web cam to capture image, and send into ALPR.




import json, shlex, subprocess

class PlateReader:


    def __init__(self):
        #webcam subprocess args
        webcam_command = "fswebcam -r 640x480 -S 20 --no-banner --quiet alpr.jpg"
        self.webcam_command_args = shlex.split(webcam_command)

        #alpr subprocess args
        alpr_command = "alpr -c eu -t hr -n 300 -j alpr.jpg"
        self.alpr_command_args = shlex.split(alpr_command)


    def webcam_subprocess(self):
        return subprocess.Popen(self.webcam_command_args, stdout=subprocess.PIPE)


    def alpr_subprocess(self):
        return subprocess.Popen(self.alpr_command_args, stdout=subprocess.PIPE)


    def alpr_json_results(self):
        self.webcam_subprocess().communicate()
        alpr_out, alpr_error = self.alpr_subprocess().communicate()

        if not alpr_error is None:
            return None, alpr_error
        elif "No license plates found." in alpr_out:
            return None, None

        try:
            return json.loads(alpr_out), None
        except ValueError, e:
            return None, e


    def read_plate(self):
        alpr_json, alpr_error = self.alpr_json_results()

        if not alpr_error is None:
            print alpr_error
            return

        if alpr_json is None:
            print "No results!"
            return

        results = alpr_json["results"]

        ordinal = 0
        for result in results:
            candidates = result["candidates"]

            for candidate in candidates:
                if candidate["matches_template"] == 1:
                    ordinal += 1
                    print "Guess {0:d}: {1:s} {2:.2f}%".format(ordinal, candidate["plate"], candidate["confidence"])


if __name__=="__main__":
    plate_reader = PlateReader()
    plate_reader.read_plate()

留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone