Enhanced logging, diagnostics, and robustness throughout

Added NLog-based logging and diagnostics to Console and WPF apps, with programmatic configuration and support for debugger output. Refactored apps to use dependency injection and Microsoft.Extensions.Hosting. Improved output layer extraction and fallback logic in detection/recognition, including objectness-class probability multiplication. Added crop saving for diagnostics. Introduced new CLI options for diagnostics. MainViewModel and MainWindow now use DI and log errors. NumberRecognitionEngine supports logging, crop saving, and robust fallback. Added Python diagnostic script. Improved error handling and argument parsing.
This commit is contained in:
MaddoScientisto 2026-02-15 18:06:03 +01:00
commit d2206a00cb
14 changed files with 571 additions and 78 deletions

33
det.py
View file

@ -42,7 +42,17 @@ number_classes = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
def get_output_layers(net):
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
unconnected = net.getUnconnectedOutLayers()
indices = []
if isinstance(unconnected, np.ndarray):
indices = unconnected.flatten()
else:
try:
indices = [u[0] if hasattr(u, '__iter__') else u for u in unconnected]
except Exception:
indices = list(unconnected)
output_layers = [layer_names[int(i) - 1] for i in indices]
return output_layers
@ -145,13 +155,15 @@ def recog_number(image):
valid_classids = []
valid_centerX = []
for i in indices:
i = i[0]
box = boxes[i]
if isinstance(i, (list, tuple, np.ndarray)):
idx = int(i[0])
else:
idx = int(i)
box = boxes[idx]
x = box[0]
valid_boxes.append(box)
valid_classids.append(class_ids[i])
valid_classids.append(class_ids[idx])
valid_centerX.append(x)
for i in range(0, len(valid_centerX)):
@ -225,20 +237,21 @@ def recog_text(image):
text = ""
for i in indices:
i = i[0]
box = boxes[i]
if isinstance(i, (list, tuple, np.ndarray)):
idx = int(i[0])
else:
idx = int(i)
box = boxes[idx]
x = box[0]
y = box[1]
w = box[2]
h = box[3]
# if center_Y_list[i] in range(int(image.shape[0] * 0.2), int(image.shape[0] * 0.8)):
plate_img = crop_image(image, round(x), round(y), round(w), round(h))
license_str = recog_number(plate_img)
draw_bounding_box(image, class_ids[i], license_str, round(x), round(y), round(x + w), round(y + h))
draw_bounding_box(image, class_ids[idx], license_str, round(x), round(y), round(x + w), round(y + h))
print(license_str)