arbeiten an Tests

This commit is contained in:
chk
2026-05-25 09:50:05 +02:00
parent 99794b944d
commit 6e770c170a
10 changed files with 65 additions and 31 deletions

View File

@@ -262,12 +262,19 @@ def main():
parser.add_argument('--dict', default='DICT_4X4_250', help="ArUco dictionary name")
parser.add_argument('-settings', type=str, default=None,
help="Json settings file containing machine KnownMarkers")
parser.add_argument('--outDir', type=str, default=None,
help="Optional directory where all output files are written")
args = parser.parse_args()
if len(args.images) != 2 or len(args.npz) != 2:
print("[ERROR] Provide exactly two images and two intrinsics NPZ files.")
sys.exit(1)
out_dir = None
if args.outDir:
out_dir = args.outDir
os.makedirs(out_dir, exist_ok=True)
img1 = cv2.imread(args.images[0])
img2 = cv2.imread(args.images[1])
draw1 = img1.copy()
@@ -484,10 +491,10 @@ def main():
})
# Save CSV & JSON
base1 = os.path.splitext(args.images[0])[0]
base2 = os.path.splitext(args.images[1])[0]
out_csv = f"{base1}_two_cam.csv"
out_json = f"{base1}_two_cam.json"
base1 = os.path.splitext(os.path.basename(args.images[0]))[0]
base2 = os.path.splitext(os.path.basename(args.images[1]))[0]
out_csv = os.path.join(out_dir, f"{base1}_two_cam.csv") if out_dir else f"{base1}_two_cam.csv"
out_json = os.path.join(out_dir, f"{base1}_two_cam.json") if out_dir else f"{base1}_two_cam.json"
try:
import csv
@@ -585,7 +592,7 @@ def main():
cv2.putText(drawPNG1, "+Z (100 mm)", z_end, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 0, 255), 2)
out_img1 = f"{base1}_two_cam_annotated.jpg"
out_img1 = os.path.join(out_dir, f"{base1}_two_cam_annotated.jpg") if out_dir else f"{base1}_two_cam_annotated.jpg"
cv2.imwrite(out_img1, draw1)
print(f"[INFO] Annotated image saved as '{out_img1}'.")
@@ -597,7 +604,7 @@ def main():
# 5) Merge BGR + alpha → RGBA transparent overlay
drawPNG_1 = cv2.merge([drawPNG1[:, :, 0], drawPNG1[:, :, 1], drawPNG1[:, :, 2], alpha])
out_png1 = f"{base1}_two_cam_overlay.png"
out_png1 = os.path.join(out_dir, f"{base1}_two_cam_overlay.png") if out_dir else f"{base1}_two_cam_overlay.png"
cv2.imwrite(out_png1, drawPNG_1)
except Exception as e:
@@ -653,14 +660,14 @@ def main():
cv2.putText(drawPNG2, "Y (-100 mm)", y_end2, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0, 255), 2)
cv2.putText(drawPNG2, "+Z (100 mm)", z_end2, cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 0, 255), 2)
out_img2 = f"{base2}_two_cam_annotated.jpg"
out_img2 = os.path.join(out_dir, f"{base2}_two_cam_annotated.jpg") if out_dir else f"{base2}_two_cam_annotated.jpg"
cv2.imwrite(out_img2, draw2)
print(f"[INFO] Annotated image saved as '{out_img2}'.")
gray2 = cv2.cvtColor(drawPNG2, cv2.COLOR_BGR2GRAY)
_, alpha2 = cv2.threshold(gray2, 0, 255, cv2.THRESH_BINARY)
drawPNG_2 = cv2.merge([drawPNG2[:, :, 0], drawPNG2[:, :, 1], drawPNG2[:, :, 2], alpha2])
out_png2 = f"{base2}_two_cam_overlay.png"
out_png2 = os.path.join(out_dir, f"{base2}_two_cam_overlay.png") if out_dir else f"{base2}_two_cam_overlay.png"
cv2.imwrite(out_png2, drawPNG_2)
print(f"[INFO] Overlay PNG saved as '{out_png2}'.")