Spaces:
Running
Running
jslmmfboom-coder commited on
Commit ·
5a4e88e
1
Parent(s): 38331a3
Perf: 提升可视化图片清晰度(max_h 300/400->600, JPEG quality 85->95)
Browse files
app.py
CHANGED
|
@@ -557,7 +557,7 @@ def _build_complex_vis_from_cache(log_entry, image_cache):
|
|
| 557 |
orig_h1, orig_w1 = img1.shape[:2]
|
| 558 |
orig_h2, orig_w2 = img2.shape[:2]
|
| 559 |
|
| 560 |
-
max_h =
|
| 561 |
scale1 = max_h / orig_h1
|
| 562 |
scale2 = max_h / orig_h2
|
| 563 |
img1_disp = cv2.resize(img1, (int(orig_w1*scale1), max_h))
|
|
@@ -608,7 +608,7 @@ def _build_complex_vis_from_cache(log_entry, image_cache):
|
|
| 608 |
n_matches = len(matches)
|
| 609 |
avg_sim = sum(s for _, _, s in matches) / max(n_matches, 1)
|
| 610 |
|
| 611 |
-
_, buffer = cv2.imencode('.jpg', canvas, [cv2.IMWRITE_JPEG_QUALITY,
|
| 612 |
img_b64 = base64.b64encode(buffer).decode('utf-8')
|
| 613 |
|
| 614 |
return {
|
|
@@ -654,7 +654,7 @@ def _build_text_vis_from_cache(log_entry, image_cache):
|
|
| 654 |
diff_words1 = words1 - words2
|
| 655 |
diff_words2 = words2 - words1
|
| 656 |
|
| 657 |
-
max_h =
|
| 658 |
scale1 = max_h / img1.shape[0]
|
| 659 |
scale2 = max_h / img2.shape[0]
|
| 660 |
img1_s = cv2.resize(img1, (int(img1.shape[1]*scale1), max_h))
|
|
@@ -687,7 +687,7 @@ def _build_text_vis_from_cache(log_entry, image_cache):
|
|
| 687 |
common_list = sorted(common_words)[:20]
|
| 688 |
|
| 689 |
canvas = cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGB2BGR)
|
| 690 |
-
_, buffer = cv2.imencode('.jpg', canvas, [cv2.IMWRITE_JPEG_QUALITY,
|
| 691 |
img_b64 = base64.b64encode(buffer).decode('utf-8')
|
| 692 |
|
| 693 |
return {
|
|
@@ -864,7 +864,7 @@ def _run_demo_pipeline(img_paths, expected_scene):
|
|
| 864 |
img = cv2.imdecode(data, cv2.IMREAD_COLOR)
|
| 865 |
if img is None:
|
| 866 |
return None
|
| 867 |
-
_, buf = cv2.imencode('.jpg', img, [cv2.IMWRITE_JPEG_QUALITY,
|
| 868 |
return f'data:image/jpeg;base64,{base64.b64encode(buf).decode("utf-8")}'
|
| 869 |
except Exception:
|
| 870 |
return None
|
|
|
|
| 557 |
orig_h1, orig_w1 = img1.shape[:2]
|
| 558 |
orig_h2, orig_w2 = img2.shape[:2]
|
| 559 |
|
| 560 |
+
max_h = 600
|
| 561 |
scale1 = max_h / orig_h1
|
| 562 |
scale2 = max_h / orig_h2
|
| 563 |
img1_disp = cv2.resize(img1, (int(orig_w1*scale1), max_h))
|
|
|
|
| 608 |
n_matches = len(matches)
|
| 609 |
avg_sim = sum(s for _, _, s in matches) / max(n_matches, 1)
|
| 610 |
|
| 611 |
+
_, buffer = cv2.imencode('.jpg', canvas, [cv2.IMWRITE_JPEG_QUALITY, 95])
|
| 612 |
img_b64 = base64.b64encode(buffer).decode('utf-8')
|
| 613 |
|
| 614 |
return {
|
|
|
|
| 654 |
diff_words1 = words1 - words2
|
| 655 |
diff_words2 = words2 - words1
|
| 656 |
|
| 657 |
+
max_h = 600
|
| 658 |
scale1 = max_h / img1.shape[0]
|
| 659 |
scale2 = max_h / img2.shape[0]
|
| 660 |
img1_s = cv2.resize(img1, (int(img1.shape[1]*scale1), max_h))
|
|
|
|
| 687 |
common_list = sorted(common_words)[:20]
|
| 688 |
|
| 689 |
canvas = cv2.cvtColor(np.array(pil_img), cv2.COLOR_RGB2BGR)
|
| 690 |
+
_, buffer = cv2.imencode('.jpg', canvas, [cv2.IMWRITE_JPEG_QUALITY, 95])
|
| 691 |
img_b64 = base64.b64encode(buffer).decode('utf-8')
|
| 692 |
|
| 693 |
return {
|
|
|
|
| 864 |
img = cv2.imdecode(data, cv2.IMREAD_COLOR)
|
| 865 |
if img is None:
|
| 866 |
return None
|
| 867 |
+
_, buf = cv2.imencode('.jpg', img, [cv2.IMWRITE_JPEG_QUALITY, 95])
|
| 868 |
return f'data:image/jpeg;base64,{base64.b64encode(buf).decode("utf-8")}'
|
| 869 |
except Exception:
|
| 870 |
return None
|