'commit'
This commit is contained in:
63
Apps/TeLaiDian/TestCV.py
Normal file
63
Apps/TeLaiDian/TestCV.py
Normal file
@@ -0,0 +1,63 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
# 确保项目根目录在 sys.path 中
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
if project_root not in sys.path:
|
||||
sys.path.append(project_root)
|
||||
|
||||
from Apps.TeLaiDian import Kit
|
||||
from Apps.TeLaiDian.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO
|
||||
|
||||
def test_cv_detection(image_path):
|
||||
print(f"开始测试 CV 检测: {image_path}")
|
||||
|
||||
if not os.path.exists(image_path):
|
||||
print(f"错误: 文件不存在 {image_path}")
|
||||
return
|
||||
|
||||
img = Kit.read_image(image_path)
|
||||
h, w = img.shape[:2]
|
||||
print(f"图片尺寸: {w}x{h}")
|
||||
print(f"当前过滤阈值: top_limit={int(h*SAFE_EXCLUDE_RATIO)}, bottom_limit={int(h*(1-BOTTOM_SAFE_EXCLUDE_RATIO))}")
|
||||
|
||||
# 1. 检测卡片
|
||||
bboxes = Kit.detect_cards_cv(image_path, top_ratio=SAFE_EXCLUDE_RATIO, bottom_ratio=BOTTOM_SAFE_EXCLUDE_RATIO)
|
||||
print(f"检测到 {len(bboxes)} 个卡片区域")
|
||||
for i, box in enumerate(bboxes):
|
||||
print(f" 卡片 {i+1}: {box}")
|
||||
|
||||
# 2. 生成 _vl.jpg (仅绿框)
|
||||
vl_path = image_path.replace(".jpg", "_vl.jpg")
|
||||
img_vl = Kit.read_image(image_path)
|
||||
for box in bboxes:
|
||||
cv2.rectangle(img_vl, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 3)
|
||||
Kit.save_image(vl_path, img_vl)
|
||||
print(f"已生成 VLM 标注图: {vl_path}")
|
||||
|
||||
# 3. 生成 _flag.jpg (绿框 + 点击点)
|
||||
flag_path = image_path.replace(".jpg", "_flag.jpg")
|
||||
img_flag = img_vl.copy()
|
||||
for box in bboxes:
|
||||
# 计算点击点:卡片中心
|
||||
center_x = (box[0] + box[2]) // 2
|
||||
center_y = (box[1] + box[3]) // 2
|
||||
|
||||
# 绘制红色点击点 (实心圆 + 十字)
|
||||
cv2.circle(img_flag, (center_x, center_y), 15, (0, 0, 255), -1)
|
||||
cv2.line(img_flag, (center_x - 30, center_y), (center_x + 30, center_y), (255, 255, 255), 3)
|
||||
cv2.line(img_flag, (center_x, center_y - 30), (center_x, center_y + 30), (255, 255, 255), 3)
|
||||
|
||||
# 标注序号
|
||||
idx = bboxes.index(box) + 1
|
||||
cv2.putText(img_flag, str(idx), (box[0] + 10, box[1] + 40), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 0, 255), 3)
|
||||
|
||||
Kit.save_image(flag_path, img_flag)
|
||||
print(f"已生成人工核对图: {flag_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
target_image = r"d:\dsWork\aiData\Output\tld_list_1768347471.jpg"
|
||||
test_cv_detection(target_image)
|
||||
Reference in New Issue
Block a user