Skip to content

Commit 6c66569

Browse files
committed
Fixed the same version issue
1 parent b979892 commit 6c66569

1 file changed

Lines changed: 65 additions & 14 deletions

File tree

examples/official/comparison_tool/sdk_comparison.py

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import subprocess
1616
import json
1717
import time
18+
import hashlib
1819
from pathlib import Path
1920
from typing import Dict, List, Optional
2021
from dataclasses import dataclass
@@ -53,16 +54,22 @@ def load_image_and_draw_overlays(image_path: str, results_dict: Optional[Dict[st
5354

5455
if results_dict:
5556
# Create separate images for each SDK with overlays
56-
for sdk_name, result in results_dict.items():
57+
sdk_names = list(results_dict.keys())
58+
color_palette = [
59+
(0, 150, 255), # Blue for first SDK
60+
(255, 0, 150), # Pink for second SDK
61+
(0, 255, 150), # Green for third SDK
62+
(255, 150, 0), # Orange for fourth SDK
63+
(150, 0, 255), # Purple for fifth SDK
64+
]
65+
66+
for i, (sdk_name, result) in enumerate(results_dict.items()):
5767
img_copy = img_rgb.copy()
5868

5969
# Draw barcode overlays directly on the image
6070
if result.success and result.barcodes:
61-
# Define colors for different SDKs
62-
if "v1" in sdk_name.lower() or "3.0.4100" in sdk_name:
63-
color = (0, 150, 255) # Blue for SDK v1
64-
else:
65-
color = (255, 0, 150) # Pink for SDK v2
71+
# Use different colors for different SDKs
72+
color = color_palette[i % len(color_palette)]
6673

6774
for i, barcode in enumerate(result.barcodes):
6875
if barcode.points and len(barcode.points) >= 4:
@@ -109,6 +116,27 @@ class SDKVersion:
109116
version: str
110117
python_path: str
111118
description: str
119+
120+
@property
121+
def unique_id(self) -> str:
122+
"""Generate a unique identifier combining version and environment path"""
123+
# Extract a short identifier from the path for uniqueness
124+
path_parts = Path(self.python_path).parts
125+
env_identifier = ""
126+
127+
# Look for environment indicators in the path
128+
for i, part in enumerate(path_parts):
129+
if part.lower() in ['envs', 'venv', 'virtualenv', 'conda']:
130+
if i + 1 < len(path_parts):
131+
env_identifier = path_parts[i + 1]
132+
break
133+
134+
# If no clear env identifier found, use a hash of the path
135+
if not env_identifier:
136+
import hashlib
137+
env_identifier = hashlib.md5(self.python_path.encode()).hexdigest()[:8]
138+
139+
return f"{self.name}_{env_identifier}"
112140

113141
class SDKVersionDetector:
114142
"""Utility class to detect SDK versions in virtual environments"""
@@ -416,12 +444,16 @@ class ResultsTableWidget(QTableWidget):
416444
def __init__(self):
417445
super().__init__()
418446
self.sdk_versions = [] # Store SDK versions for header updates
447+
self.sdk_id_to_version = {} # Map unique_id to SDKVersion objects
419448
self.setup_table()
420449
self.itemSelectionChanged.connect(self.on_selection_changed)
421450

422451
def update_sdk_headers(self, sdk_versions: List[SDKVersion]):
423452
"""Update table headers with actual SDK version names"""
424453
self.sdk_versions = sdk_versions
454+
# Create mapping from unique_id to SDKVersion for display purposes
455+
self.sdk_id_to_version = {sdk.unique_id: sdk for sdk in sdk_versions}
456+
425457
if len(sdk_versions) >= 2:
426458
headers = [
427459
"Image",
@@ -454,6 +486,12 @@ def setup_table(self):
454486
self.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
455487
self.setSelectionMode(QTableWidget.SelectionMode.SingleSelection)
456488

489+
def get_display_name(self, unique_id: str) -> str:
490+
"""Get the display name for a unique SDK ID"""
491+
if unique_id in self.sdk_id_to_version:
492+
return self.sdk_id_to_version[unique_id].name
493+
return unique_id # Fallback to unique_id if not found
494+
457495
def add_comparison_result(self, image_path: str, results: Dict[str, ProcessingResult]):
458496
"""Add a comparison result to the table"""
459497
row = self.rowCount()
@@ -672,6 +710,7 @@ def __init__(self):
672710
self.setup_ui()
673711
self.current_image = None
674712
self.results = {}
713+
self.sdk_id_to_version = {} # Map unique_id to SDKVersion objects
675714

676715
def setup_ui(self):
677716
layout = QVBoxLayout(self)
@@ -747,6 +786,9 @@ def setup_ui(self):
747786

748787
def update_sdk_labels(self, sdk_versions: List[SDKVersion]):
749788
"""Update SDK version labels with actual version names"""
789+
# Update the mapping
790+
self.sdk_id_to_version = {sdk.unique_id: sdk for sdk in sdk_versions}
791+
750792
if len(sdk_versions) >= 2:
751793
self.sdk1_label.setText(f"📊 {sdk_versions[0].name}")
752794
self.sdk2_label.setText(f"📊 {sdk_versions[1].name}")
@@ -757,6 +799,12 @@ def update_sdk_labels(self, sdk_versions: List[SDKVersion]):
757799
self.sdk1_label.setText("📊 Configure SDK Version 1")
758800
self.sdk2_label.setText("📊 Configure SDK Version 2")
759801

802+
def get_display_name(self, unique_id: str) -> str:
803+
"""Get the display name for a unique SDK ID"""
804+
if unique_id in self.sdk_id_to_version:
805+
return self.sdk_id_to_version[unique_id].name
806+
return unique_id # Fallback to unique_id if not found
807+
760808
def show_comparison(self, image_path: str, results: Dict[str, ProcessingResult]):
761809
"""Show side-by-side comparison for an image"""
762810
self.current_image = image_path
@@ -798,9 +846,11 @@ def show_comparison(self, image_path: str, results: Dict[str, ProcessingResult])
798846
self.sdk2_scene.addPixmap(sdk2_pixmap)
799847
self.sdk2_scene.setSceneRect(sdk2_pixmap.rect())
800848

801-
# Update labels with actual SDK names
802-
self.sdk1_label.setText(f"📊 {sdk_names[0]}")
803-
self.sdk2_label.setText(f"📊 {sdk_names[1]}")
849+
# Update labels with actual SDK names (use display names instead of unique IDs)
850+
sdk1_display_name = self.get_display_name(sdk_names[0])
851+
sdk2_display_name = self.get_display_name(sdk_names[1])
852+
self.sdk1_label.setText(f"📊 {sdk1_display_name}")
853+
self.sdk2_label.setText(f"📊 {sdk2_display_name}")
804854

805855
# Update barcode result text areas
806856
self.update_barcode_text_area(self.sdk1_results_text, results[sdk_names[0]])
@@ -810,8 +860,8 @@ def show_comparison(self, image_path: str, results: Dict[str, ProcessingResult])
810860
result1 = results[sdk_names[0]]
811861
result2 = results[sdk_names[1]]
812862
summary = (f"📊 {os.path.basename(image_path)} | "
813-
f"{sdk_names[0]}: {len(result1.barcodes)} barcodes ({result1.processing_time:.3f}s) | "
814-
f"{sdk_names[1]}: {len(result2.barcodes)} barcodes ({result2.processing_time:.3f}s)")
863+
f"{sdk1_display_name}: {len(result1.barcodes)} barcodes ({result1.processing_time:.3f}s) | "
864+
f"{sdk2_display_name}: {len(result2.barcodes)} barcodes ({result2.processing_time:.3f}s)")
815865
self.summary_label.setText(summary)
816866
elif len(sdk_names) == 1:
817867
# Only one SDK result available
@@ -826,7 +876,8 @@ def show_comparison(self, image_path: str, results: Dict[str, ProcessingResult])
826876
self.sdk1_scene.addPixmap(sdk1_pixmap)
827877
self.sdk1_scene.setSceneRect(sdk1_pixmap.rect())
828878

829-
self.sdk1_label.setText(f"📊 {sdk_names[0]}")
879+
sdk1_display_name = self.get_display_name(sdk_names[0])
880+
self.sdk1_label.setText(f"📊 {sdk1_display_name}")
830881
self.sdk2_label.setText("📊 No comparison data")
831882

832883
# Update text areas
@@ -836,7 +887,7 @@ def show_comparison(self, image_path: str, results: Dict[str, ProcessingResult])
836887

837888
result1 = results[sdk_names[0]]
838889
summary = (f"📊 {os.path.basename(image_path)} | "
839-
f"{sdk_names[0]}: {len(result1.barcodes)} barcodes ({result1.processing_time:.3f}s)")
890+
f"{sdk1_display_name}: {len(result1.barcodes)} barcodes ({result1.processing_time:.3f}s)")
840891
self.summary_label.setText(summary)
841892
else:
842893
# No results, just show the base image
@@ -1280,7 +1331,7 @@ def run(self):
12801331
for image_path in self.image_files:
12811332
for sdk_version in self.sdk_versions:
12821333
result = self.process_single_image(image_path, sdk_version)
1283-
self.result_ready.emit(image_path, sdk_version.name, result)
1334+
self.result_ready.emit(image_path, sdk_version.unique_id, result)
12841335

12851336
self.processing_complete.emit()
12861337

0 commit comments

Comments
 (0)