Pythone APIs.
To use the engines, import 'PyEvo.py' module. For its path, refer to SDK contents.
Example for Snapshot Engine
import ctypes
import glob
import PyEvo
def get_img_data(fpath):
import PIL.Image
pf = -1
pil_img = PIL.Image.open(fpath)
if pil_img.mode == 'L':
pf = 0
elif pil_img.mode == 'YCbCr':
pf = 10
elif pil_img.mode == 'RGB':
pf = 20
else:
raise RuntimeError('Unsupported Pixel Formats')
img = PyEvo.Image()
img.planes[0] = ctypes.cast(ctypes.c_char_p(pil_img.tobytes()), ctypes.c_void_p)
img.width = pil_img.width
img.height = pil_img.height
img.pf = pf
img.strides[0] = 0
return img
def get_enc_img(fpath):
encimg = bytes()
try:
f = open(fpath, 'rb')
encimg = f.read()
except:
print("Opening the file '{}'".format(fpath))
return encimg
def lpd_judge_cb(img_size, rects, confidences, num, results):
'''
Arguments
img_size : Array of 'PyEvo.Rect' type.
There is only one element which describes size of the input image.
rects : Array of 'PyEvo.Rect' type.
Describe bounding boxes of all the detected license plates.
confidences : Array of float type.
Describe confidences of all the detected license plates.
Ranges of the values are between 0 and 100.
num : Single value of int type.
Total number of detected license plates.
results : Array of int type.
Determine whether each detected license plate is correct (0: incorrect, 1: correct).
By default, all the elements are 0s.
'''
img_sz = img_size[0]
print("")
fmtstr = "Image Size : Width({}), Height({})";
print(fmtstr.format(img_sz.width, img_sz.height))
fmtstr = "Detection Count: {}";
print(fmtstr.format(num))
print("")
for i in range(num):
print(" Index : {}".format(i))
fmtstr = " Bounding Box: x({}), y({}), width({}), height({})";
print(fmtstr.format(rects[i].x, rects[i].y, rects[i].width, rects[i].height))
print(" Confidence : {:.2f}%".format(confidences[i]))
print("--------------------------------------------")
if lpd_judge_cb.judgement_type == "the best":
best = -1
maxarea = 0
for i in range(num):
area = rects[i].width * rects[i].height;
if (area > maxarea) and (confidences[i] >= lpd_judge_cb.min_confidence):
maxarea = area
best = i
if best >= 0: results[best] = 1
elif lpd_judge_cb.judgement_type == "all":
for i in range(num): results[i] = 1
else:
pass
return 0
def print_lpi(lpi):
result = lpi.gather()
fmtstr = "String : '{}'\n"
fmtstr += "Position: x({}), y({}), width({}), height({})\n"
fmtstr += "LP-Type : {} ({:.2f}%)"
for info in result:
output = fmtstr.format(info['string'],
info['position'].x,
info['position'].y,
info['position'].width,
info['position'].height,
info['lp_type'],
info['lp_conf'])
print(output)
input_source = 'ImageFile'
use_lpd_judgement = False
if use_lpd_judgement:
lpd_judge_cb.judgement_type = "the best"
lpd_judge_cb.min_confidence = 10.0
count = 0
img_files = glob.glob('F:\\Temp2\\*.jpg')
total = len(img_files)
if total == 0:
print("There is no image file.")
quit()
ddi = PyEvo.DDI()
PyEvo.initialize(None, None, ddi)
info = ddi.get()
print(info)
print()
del ddi
sse = PyEvo.SSEngine()
sse.init('KOR', None)
search_rect = sse.get_param_search_rect()
print("<< Search Rectangle >>")
print(f' x : {search_rect.x}')
print(f' y : {search_rect.y}')
print(f' width : {search_rect.width}')
print(f' height: {search_rect.height}')
if use_lpd_judgement:
sse.set_param_lpd_judge_cb(lpd_judge_cb)
for img_path in img_files:
print("\n=====================================")
print("[{}]".format(img_path))
if input_source == "ImageFile":
lpi = sse.run_with_imgfile(img_path)
elif input_source == "ImageData":
lpi = sse.run_with_imgdata(get_img_data(img_path))
else:
encimg = get_enc_img(img_path)
lpi = sse.run_with_encimg(encimg)
if not lpi.is_empty():
print("")
print_lpi(lpi)
del lpi
count += 1
sse.deinit()
del sse
percent = (count / total) * 100.0;
print("\n\n{} / {} ({}%) passed.".format(count, total, percent))
Example for Triggered Snapshot Engine
import time
import ctypes
import threading
import PyEvo
def lpd_judge_cb(imgsz, rects, confidences, num, results):
'''
Arguments
imgsz : Array of 'PyEvo.Rect' type.
There is only one element which describes size of the input image.
rects : Array of 'PyEvo.Rect' type.
Describe bounding boxes of all the detected license plates.
confidences : Array of float type.
Describe confidences of all the detected license plates.
Ranges of the values are between 0 and 100.
num : Single value of int type.
Total number of detected license plates.
results : Array of int type.
Determine whether each detected license plate is correct (0: incorrect, 1: correct).
By default, all the elements are 0s.
'''
_imgsz = imgsz[0]
print("")
fmtstr = "Image Size : Width({}), Height({})";
print(fmtstr.format(_imgsz.width, _imgsz.height))
fmtstr = "Detection Count: {}";
print(fmtstr.format(num))
print("")
for i in range(num):
print(" Index : {}".format(i))
fmtstr = " Bounding Box: x({}), y({}), width({}), height({})";
print(fmtstr.format(rects[i].x, rects[i].y, rects[i].width, rects[i].height))
print(" Confidence : {:.2f}%".format(confidences[i]))
print("--------------------------------------------")
if lpd_judge_cb.judgement_type == "the best":
best = -1
maxarea = 0
for i in range(num):
area = rects[i].width * rects[i].height;
if (area > maxarea) and (confidences[i] >= lpd_judge_cb.min_confidence):
maxarea = area
best = i
if best >= 0: results[best] = 1
elif lpd_judge_cb.judgement_type == "all":
for i in range(num): results[i] = 1
else:
pass
return 0
def print_lpi(lpi):
result = lpi.gather()
fmtstr = "String : '{}'\n"
fmtstr += "Position: x({}), y({}), width({}), height({})\n"
fmtstr += "LP-Type : {} ({:.2f}%)"
for info in result:
output = fmtstr.format(info['string'],
info['position'].x,
info['position'].y,
info['position'].width,
info['position'].height,
info['lp_type'],
info['lp_conf'])
print(output)
def timer_handler():
global tsse
global img_dir
global is_continue
global trigger_timer
(lpi, pic) = tsse.trigger()
if not lpi.is_empty():
print("")
print_lpi(lpi)
del lpi
pic.save_in_jpeg('{}\\{}.jpg'.format(img_dir, pic.get_time(1)))
del pic
if is_continue:
threading.Timer(1, timer_handler).start()
use_lpd_judgement = False
url = 'F:\\Temp1\\2014-11-24_.mkv'
img_dir = 'F:\\Temp7'
is_continue = True
if use_lpd_judgement:
lpd_judge_cb.judgement_type = "the best"
lpd_judge_cb.min_confidence = 10.0
ddi = PyEvo.DDI()
PyEvo.initialize(None, None, ddi)
info = ddi.get()
print(info)
print()
del ddi
tsse = PyEvo.TSSEngine()
tsse.init_ipproto('KOR', None, url)
search_rect = tsse.get_param_search_rect()
print("<< Search Rectangle >>")
print(f' x : {search_rect.x}')
print(f' y : {search_rect.y}')
print(f' width : {search_rect.width}')
print(f' height: {search_rect.height}')
if use_lpd_judgement:
tsse.set_param_lpd_judge_cb(lpd_judge_cb)
threading.Timer(1, timer_handler).start()
for num in range(5):
time.sleep(1.0)
is_continue = False
time.sleep(1.5)
tsse.deinit()
del tsse
Example for Fully Automatic Video Engine
import time
import ctypes
import PyEvo
def lpd_judge_cb(imgsz, rects, confidences, num, results):
'''
Arguments
imgsz : Array of 'PyEvo.Rect' type.
There is only one element which describes size of the input image.
rects : Array of 'PyEvo.Rect' type.
Describe bounding boxes of all the detected license plates.
confidences : Array of float type.
Describe confidences of all the detected license plates.
Ranges of the values are between 0 and 100.
num : Single value of int type.
Total number of detected license plates.
results : Array of int type.
Determine whether each detected license plate is correct (0: incorrect, 1: correct).
By default, all the elements are 0s.
'''
_imgsz = imgsz[0]
print("")
fmtstr = "Image Size : Width({}), Height({})";
print(fmtstr.format(_imgsz.width, _imgsz.height))
fmtstr = "Detection Count: {}";
print(fmtstr.format(num))
print("")
for i in range(num):
print(" Index : {}".format(i))
fmtstr = " Bounding Box: x({}), y({}), width({}), height({})";
print(fmtstr.format(rects[i].x, rects[i].y, rects[i].width, rects[i].height))
print(" Confidence : {:.2f}%".format(confidences[i]))
print("--------------------------------------------")
if lpd_judge_cb.judgement_type == "the best":
best = -1
maxarea = 0
for i in range(num):
area = rects[i].width * rects[i].height;
if (area > maxarea) and (confidences[i] >= lpd_judge_cb.min_confidence):
maxarea = area
best = i
if best >= 0: results[best] = 1
elif lpd_judge_cb.judgement_type == "all":
for i in range(num): results[i] = 1
else:
pass
return 0
def print_output(lpi, gop):
results = lpi.gather()
assert (len(results) == 1)
info = results[0]
fmtstr = "String: '{}'\n"
fmtstr += "LP-Type: {} ({:.2f}%)"
print(fmtstr.format(info['string'], info['lp_type'], info['lp_conf']))
for i in range(gop.get_num_pic()):
gop.select_pic(i)
pos = gop.get_pos_in_pic()
fmtstr = "Position: x({}), y({}), width({}), height({})"
print(fmtstr.format(pos.x, pos.y, pos.width, pos.height))
time_utc = gop.get_pic_time()
time_sec = time_utc // 1000
time_ms = time_utc % 1000
bdt = time.localtime(time_sec)
fmtstr = "Time: {}-{}-{} {}:{}:{}.{}"
print(fmtstr.format(bdt.tm_year,
bdt.tm_mon,
bdt.tm_mday,
bdt.tm_hour,
bdt.tm_min,
bdt.tm_sec,
time_ms))
heading = gop.get_head_dir()
fmtstr = f'Heading Direction: {heading}'
print(fmtstr)
print("")
global output_dir
if gop.get_num_pic() < 2:
path = f"{output_dir}\\{info['string']}.jpg"
gop.save_pic_in_jpeg(path)
else:
path = f"{output_dir}\\{info['string']}.tiff"
gop.save_all_in_tiff(path)
video_type = "IPProto"
url = 'F:\\Temp1\\2014-11-24_.mkv'
use_lpd_judgement = False
gic = { 'admin': None, 'dev': None }
output_dir = 'F:\\Temp4'
if use_lpd_judgement:
lpd_judge_cb.judgement_type = "the best"
lpd_judge_cb.min_confidence = 10.0
ddi = PyEvo.DDI()
PyEvo.initialize(None, None, ddi)
info = ddi.get()
print(info)
print()
del ddi
if video_type == 'GenICam':
gic['admin'] = PyEvo.GIC.Admin()
gic['admin'].update_dev_list()
num = gic['admin'].get_num_dev()
if num > 0:
for idx in range(num):
gic['admin'].select_dev(idx)
info = gic['admin'].get_dev_info()
print(f'Device Information: {info}')
print('')
gic['admin'].select_dev(0)
gic['dev'] = gic['admin'].open_dev()
num = gic['dev'].get_num_ds()
if num > 0:
print(f'Number of the data streams : {num}')
else:
del gic['dev']
del gic['admin']
quit()
else:
del gic['admin']
quit()
fave = PyEvo.FAVEngine()
if video_type == 'IPProto':
fave.init_ipproto('KOR', None, url)
else:
fave.init_genicam('KOR', None, gic['dev'], 0)
output = fave.get_param_output()
output.headDir = 1
fave.set_param_output(output)
fave.set_param_gop_size(1)
if use_lpd_judgement:
fave.set_param_lpd_judge_cb(lpd_judge_cb)
for num in range(3):
(lpi, gop) = fave.pop_lpi()
if lpi.is_empty() and gop.is_empty():
break
print_output(lpi, gop)
del lpi, gop
fave.deinit()
del fave
if video_type == 'GenICam':
del gic['dev']
del gic['admin']
Example for camera calibration
import PyEvo
def print_lpi(lpi):
result = lpi.gather()
fmtstr = " String : '{}'\n"
fmtstr += " Position : x({}), y({}), width({}), height({})\n"
fmtstr += " LP-Type : {} ({:.2f}%)\n"
for info in result:
output = fmtstr.format(info['string'],
info['position'].x,
info['position'].y,
info['position'].width,
info['position'].height,
info['lp_type'],
info['lp_conf'])
print(output)
print("")
img_path = 'F:\\Temp3\\Test-180-3.png'
PyEvo.initialize('latency')
fisheye_model = PyEvo.CC.Fisheye('Test')
max_resol = fisheye_model.get_max_resol()
output_sz = fisheye_model.get_output_size()
print(f'Max resolution: {max_resol.width} x {max_resol.height}')
print(f'Output Size: {output_sz.width} x {output_sz.height}')
print('')
sse = PyEvo.SSEngine()
sse.init('KOR', 'FP32:CPU')
pic = fisheye_model.rectify_with_imgfile(img_path)
img = pic.get_image()
lpi = sse.run_with_imgdata(img)
if not lpi.is_empty():
print('')
print_lpi(lpi)
sse.free_lpi(lpi)
pic.save_jpeg('F:\\Temp3\\rectified_img.jpg')
del pic
sse.deinit()
del sse
del fisheye_model