Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/benchmark/benchmark_blur.py
641 views
1
import io
2
3
import numpy as np
4
from PIL import Image, ImageFilter
5
6
from plate_recognition import parse_arguments, recognition_api
7
8
9
def main():
10
args = parse_arguments()
11
scores = []
12
for path in args.files:
13
blur_amount = 0
14
init_value = ""
15
while True:
16
# Blur image
17
image = Image.open(path)
18
if image.height > 1080:
19
image = image.resize((int(image.width * 1080 / image.height), 1080))
20
elif image.width > 1980:
21
image = image.resize((1980, int(image.height * 1980 / image.width)))
22
if blur_amount > 0:
23
image = image.filter(ImageFilter.GaussianBlur(radius=blur_amount))
24
buffer = io.BytesIO()
25
image.save(buffer, "jpeg")
26
buffer.seek(0)
27
28
# Do prediction
29
api_res = recognition_api(
30
buffer,
31
args.regions,
32
args.api_key,
33
args.sdk_url,
34
camera_id=args.camera_id,
35
)
36
if not init_value:
37
init_value = api_res["results"][0]["plate"]
38
elif not api_res["results"] or init_value != api_res["results"][0]["plate"]:
39
break
40
blur_amount += 0.5
41
scores.append(blur_amount)
42
print(path, blur_amount)
43
print("Blur score", np.mean(scores))
44
45
46
if __name__ == "__main__":
47
main()
48
49