This is the 29th day of my participation in the August Wenwen Challenge.More challenges in August

Hardware and software Environment

  • Intel(R) Xeon(R) CPU E5-1607 v4 @ 3.10GHz
  • GTX 1070 Ti 32G
  • Ubuntu 18.04 64 – bit
  • Anaconda with python 3.6
  • tensorflow-gpu
  • keras
  • Opencv rule 3.4.3

HyperLPR profile

HyperLPR is a high performance Chinese license plate recognition open source project based on deep learning. The address is github.com/zeusees/Hyp… , written in Python, it also supports Linux, Android, iOS, Windows and other mainstream platforms. It has a good recognition rate and currently supports license plate types including

  • Single blue card
  • Yellow line
  • New energy license plate
  • White police plate
  • Embassy/Hong Kong and Macau plates
  • Coach license plate

HyperLPR detection process

  • useopencvtheHAAR CascadeCheck the approximate location of the license plate
  • ExtendA rectangular region of the approximate position detected
  • Use something likeMSERIn the manner of multistage binarization andRANSACFit the upper and lower boundaries of the license plate
  • useCNN RegressionReturn license plate left and right boundary
  • An algorithm based on texture field is used to correct license plate tilt
  • useCNNSlide window cut character
  • useCNNIdentify the character

HyperLPR installation

git clone https://github.com/zeusees/HyperLPR.git
cd HyperLPR
Copy the code

The project supports both PYTHon2 and Python3, but differs in directory structure, hyperlPR and HeperlPR_py3. My environment is Python3 and Anaconda. Copies the hyperlpr_py3 folder directly to the ~ / anaconda3 / lib/python3.6 / site – packages/ok

The test results

The picture

from hyperlpr_py3 import pipline as pp
import cv2
import click

@click.command()
@click.option('--image', help = 'input image')
def main(image):
    img = cv2.imread(image)
    img,res = pp.SimpleRecognizePlateByE2E(img)
    print(res)

if __name__ == '__main__':
    main()

Copy the code

Some identification results were wrong due to the shooting Angle.

longjing@FR:~/Work/gogs/LPR$ python test_image.py --image demo_images/demo1.png Using TensorFlow backend. 2018-12-18 15:28:27. 628782: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not Compiled to Use: AVX2 FMA 2018-12-18 15:28:27.765931: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: name: GeForce GTX 1070 Ti Major: 6 Minor: 1 memoryClockRate(GHz): 1.683 pciBusID: 0000:03:00. 7.93GiB freeMemory: 7.15GiB 2018-12-18 15:28:27.765967: I tensorflow/core/common_runtime/ GPU /gpu_device.cc:1511] Adding Visible GPU Devices: 0 2018-12-18 15:28:28.030061: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-12-18 15:28:28.030097: I tensorflow/core/ Common_Runtime/GPU /gpu_device.cc:988] 0 2018-12-18 15:28:28.030105: I tensorflow/core/common_runtime/ GPU /gpu_device.cc:1001] 0: N 2018-12-18 15:28:28.030306: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6899 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070 Ti, PCI bus ID: 0000:03:00, compute Capability: 6.1) RES MIN R6G81 K01C 0.6178697198629379 RES 1035 K03 0.5994847059249878 RES K032301 K030X 0.824301564693451 RES JK0330 Guijin JK0330 0.9602108970284462 RES Fujian CR8W CRM1 0.6328456625342369 res 1NX888 Cloud A Jiangxi X881 0.5053929431097848 res Guianx889 Guianx889 JC3732 JC3732 0.8844872457640511 res 1T687 L87 0.984427673476083 RES JD1687 0.9756925020899091 RES JC3732 0.8844872457640511 0.6002845267454783 [[], 'K03 ', [[], 'K03 ', 0.5994847059249878], [[], 'K030X', , [[], 'JK0330', 0.9602108970284462], [[], 'CRM1', 0.6328456625342369], [[],' cloud A gan X881', 0.5053929431097848], [[], 'Guanx889 ', 0.984427673476083], [[],' gujd1687 ', 0.9756925020899091], [[], 'gujc3732 ', 0.8844872457640511], [[], 'L87, 0.6002845267454783]Copy the code

Video file

So essentially just like the image, we’re still using the OpencV interface

# -*- coding: UTF-8 -*- # @time: 18-12-18 PM 3:05 # @author: xugaoxiang # @email: [email protected] # @website: https://xugaoxiang.com # @file : test_video_file.py # @software: PyCharm # python test_video_file.py --video test.mp4 import time import cv2 from hyperlpr_py3 import pipline as pp import click @click.command() @click.option('--video', help = 'input video file') def main(video): print("[INFO] starting video stream..." ) # vs = VideoStream(SRC =0).start() stream = cv2.videocapture (video) time.sleep(2.0) while True: # grab the frame from the threaded video stream grabbed, frame = stream.read() if not grabbed: print('No data, break.') break _, res = pp.SimpleRecognizePlate(frame) # convert the input frame from BGR to RGB then resize it to have # a width of 750px  (to speedup processing) # rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # rgb = imutils.resize(frame, width = 750) # r = frame.shape[1] / float(rgb.shape[1]) cv2.putText(frame, str(res), (50, 50), FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 255), 2) cv2.imshow("Frame", frame) key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q"): break # do a bit of cleanup cv2.destroyAllWindows() stream.release() if __name__ == '__main__': main()Copy the code

The program runs and prints as follows, and the recognition rate is still ok. However, due to the time-consuming identification and detection itself, from the screen, it is just like slow playback, and the upper application needs to carry out frame loss processing according to its own needs

longjing@FR:~/Work/gogs/LPR$ python test_video_file.py --video ~/backup/lpr/2s_lpr.mp4 Using TensorFlow backend. The 2018-12-18 16:00:17. 067081: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not Compiled to Use: AVX2 FMA 2018-12-18 16:00:17.203116 I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: name: GeForce GTX 1070 Ti Major: 6 Minor: 1 memoryClockRate(GHz): 1.683 pciBusID: 0000:03:00. 7.93GiB freeMemory: 7.12GiB 2018-12-18 16:00:17.203152: I tensorflow/core/common_runtime/ GPU /gpu_device.cc:1511] Adding Visible GPU Devices :0 2018-12-18 16:00:17.471942: I tensorflow/core/common_runtime/ GPU /gpu_device.cc:1511] Adding Visible GPU Devices :0 2018-12-18 16:00:17.471942: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-12-18 16:00:17.471983: I tensorflow/core/common_runtime/ GPU /gpu_device.cc:988] 0 2018-12-18 16:00:17.471991: I tensorflow/core/common_runtime/ GPU /gpu_device.cc:1001] 0: N 2018-12-18 16:00:17.472190: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6875 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070 Ti, PCI bus ID: 0000:03:00.0, compute Capability: 6.1) [INFO] Starting video stream... License plate: Shanghai B28600 Similarity: 0.9864972574370248 License plate: Shanghai B28600 Similarity: 0.9910101975713458 License plate: Shanghai B28600 similarity: 0.9908801657812936 License plate: Shanghai B28600 similarity: 0.9916305116244725... . .Copy the code

IPC

It’s like a video file. It’s straight to the code

# -*- coding: UTF-8 -*- # @time: 18-12-18 PM 3:05 # @author: xugaoxiang # @email: [email protected] # @website: https://xugaoxiang.com # @file : test_ipc.py # @software: PyCharm # python test_ipc. Py -- -- video RTSP: / / admin: [email protected]:554 / ISAPI/streaming/channels/from 101 imutils.video import VideoStream import time import cv2 from hyperlpr_py3 import pipline as pp import click @click.command() @click.option('--video', help = 'input video, ipcamera url or usb camera index.') def main(video): print("[INFO] starting video stream..." ) # vs = VideoStream(SRC =0).start() vs = VideoStream(video).start() time.sleep(2.0) while True: # grab the frame from the threaded video stream frame = vs.read() img, res = pp.SimpleRecognizePlate(frame) print(res) # convert the input frame from BGR to RGB then resize it to have # a width of 750px (to speedup processing) # rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # rgb = imutils.resize(frame, width = 750) # r = frame.shape[1] / float(rgb.shape[1]) cv2.putText(frame, str(res), (50, 50), FONT_HERSHEY_SIMPLEX, 0.75, (0, 255, 255), 2) cv2.imshow("Frame", frame) key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q") : break # do a bit of cleanup cv2.destroyAllWindows() vs.stop() if __name__ == '__main__': main()Copy the code

Graphical detection tools

Enthusiastic developers on the basis of the original framework, using Qt to cover it with a beautiful shell, convenient for those who are not used to using the command line shoes, very good

Q & A

Q1

module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'
Copy the code

or

longjing@FR:~/Work/gogs/LPR$ python test_video_file.py Using TensorFlow backend. Traceback (most recent call last): File "test_video_file.py", line 12, in <module> from hyperlpr_py3 import pipline as pp File "/home/longjing/Work/gogs/LPR/hyperlpr_py3/pipline.py", line 5, in <module> from . import segmentation File "/home/longjing/Work/gogs/LPR/hyperlpr_py3/segmentation.py", line 16, in <module> from keras.models import Sequential File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/set py", line 3, In < module > from the import utils File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/utils/set p y", line 6, in <module> from . import conv_utils File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/utils/conv_utils py", line 9, in < module > from the. The import backend as K File "/ home/longjing/anaconda3 / lib/python3.6 / site - packages/keras/backend/set py", line 89, in <module> from .tensorflow_backend import * File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/backend/tensorflow_backend py", line 6, in <module> from tensorflow.python.framework import ops as tf_ops ModuleNotFoundError: No module named 'tensorflow.python.framework'Copy the code

A1

Reinstall tensorFlow-GPU. Install the CPU version if you don’t have a GPU

pip install --upgrade tensorflow-gpu
Copy the code

Q2

Tensorflow-gpu is installed, and a message is displayed indicating that the module is missing during startup

longjing@FR:~/Work/github/HyperLPR$ python demo_py3.py Using TensorFlow backend. Traceback (most recent call last): File "demo_py3.py", line 41, in <module> import HyperLPRLite as pr File "/home/longjing/Work/github/HyperLPR/HyperLPRLite.py", line 4, in <module> from keras import backend as K File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/set py", line 3, In < module > from the import utils File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/utils/set p y", line 6, in <module> from . import conv_utils File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/utils/conv_utils py", line 9, in < module > from the. The import backend as K File "/ home/longjing/anaconda3 / lib/python3.6 / site - packages/keras/backend/set py", line 89, in <module> from .tensorflow_backend import * File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/keras/backend/tensorflow_backend py", line 5, In < module > import tensorflow as tf File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/set p y", line 24, in <module> from tensorflow.python import pywrap_tensorflow # pylint: Disable = unused - the import File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/set p y", line 88, in <module> from tensorflow.python import keras File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras/set py", line 24, in <module> from tensorflow.python.keras import activations File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras/activations/set py", line 22, in <module> from tensorflow.python.keras._impl.keras.activations import elu File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras _impl keras/set py", line 21, in <module> from tensorflow.python.keras._impl.keras import activations File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras _impl keras/activations. Py", line 23, in <module> from tensorflow.python.keras._impl.keras import backend as K File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras _impl keras/backend. Py", line 37, in <module> from tensorflow.python.layers import base as tf_base_layers File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/the layers/base. Py", line 25, in <module> from tensorflow.python.keras.engine import base_layer File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras/engine/set py", line 23, in <module> from tensorflow.python.keras.engine.base_layer import InputSpec File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras/engine/base_layer py", line 35, in <module> from tensorflow.python.keras import backend File "/ home/longjing anaconda3 / lib/python3.6 / site - packages/tensorflow/python/keras/backend/set py", line 22, in <module> from tensorflow.python.keras._impl.keras.backend import abs ImportError: cannot import name 'abs'Copy the code

A2

Uninstall Tensorflow-GPU and Protobuf, then reinstall Tensorflow-GPU, PIP will automatically install Protobuf for you during tensorflow-GPU installation

pip uninstall tensorflow-gpu
pip uninstall protobuf
pip install --upgrade tensorflow-gpu
Copy the code

The resources

  • Github.com/zeusees/Hyp…
  • www.tensorflow.org/install/pip
  • Github.com/tensorflow/…
  • Pypi.org/project/pro…