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

2
.gitignore vendored
View File

@@ -7,3 +7,5 @@ public/snapshots/
# Aruco detection results
test/data/screenShots/*.json
*_testResults/

Binary file not shown.

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}'.")

View File

@@ -5,11 +5,40 @@
"image":[
{
"timestamp":11778819665744,
"file":"test/data/screenShots/snapshot_video0_11778819665744.jpg"
"file":"test/data/screenShots/snapshot_video0_11778819665744.jpg",
"camera":"c310",
"callibration":"data/settings/callibration_cam0.npz"
},
{
"timestamp":11778819665744,
"file":"test/data/screenShots/snapshot_video1_11778819665744.jpg"
"file":"test/data/screenShots/snapshot_video1_11778819665744.jpg",
"camera":"c310",
"callibration":"data/settings/callibration_cam0.npz"
}
]
},
{
"name":"Test 1: 45° unterarm",
"robot":"test/data/robot/robot.json",
"timestamp":1779690911822,
"image":[
{
"timestamp":1779690911822,
"file":"test/data/screenShots/snapshot_video0_1779690911822.jpg",
"camera":"c310",
"callibration":"data/settings/callibration_cam0.npz"
},
{
"timestamp":1779690911822,
"file":"test/data/screenShots/snapshot_video0_1779690911822.jpg",
"camera":"c310",
"callibration":"data/settings/callibration_cam0.npz"
},
{
"timestamp":1779690911822,
"file":"test/data/screenShots/1779690911822_DSCF1382.JPG",
"camera":"XT1",
"callibration":"data/callibration/XT1-16mm28-1mFokus_f8/callibration_XT1-16mm_1m_f8.npz"
}
]
}

View File

@@ -1,6 +1,5 @@
const { execSync } = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const BASE_PATH = path.join(__dirname, '..');
@@ -10,43 +9,40 @@ const screenshotFiles = [
'snapshot_video1_1778819665744.jpg',
];
let tempDir;
const SOURCE_DIR = path.join(__dirname, 'data', 'screenShots');
const DEST_DIR = path.join(__dirname, 'data', 'screenshots', '1778819665744_twoCam_testResults');
describe('Camera Pose Script', () => {
beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'AA_readTwoImages-'));
const sourceDir = path.join(__dirname, 'data', 'screenShots');
if (!fs.existsSync(DEST_DIR)) {
fs.mkdirSync(DEST_DIR, { recursive: true });
}
screenshotFiles.forEach((file) => {
const src = path.join(sourceDir, file);
const dst = path.join(tempDir, file);
const src = path.join(SOURCE_DIR, file);
if (!fs.existsSync(src)) {
throw new Error(`Missing test fixture screenshot: ${src}`);
}
fs.copyFileSync(src, dst);
});
});
afterEach(() => {
if (tempDir && fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
// Keep generated outputs for inspection.
});
test('should execute readTwoImages without modifying shared fixtures', () => {
const strFile0 = path.join(tempDir, 'snapshot_video0_1778819665744.jpg');
const strFile1 = path.join(tempDir, 'snapshot_video1_1778819665744.jpg');
const strFile0 = path.join(SOURCE_DIR, 'snapshot_video0_1778819665744.jpg');
const strFile1 = path.join(SOURCE_DIR, 'snapshot_video1_1778819665744.jpg');
const command2 = `${PYTHON_CMD} "${path.join(BASE_PATH, 'programs/readTwoImages.py')}" \
-i "${strFile0}" \
-i "${strFile1}" \
-npz "${path.join(BASE_PATH, 'data/settings/callibration_cam0.npz')}" \
-npz "${path.join(BASE_PATH, 'data/settings/callibration_cam1.npz')}" \
-settings "${path.join(BASE_PATH, 'data/settings/settings1m.json')}"`;
-settings "${path.join(BASE_PATH, 'data/settings/settings1m.json')}" \
--outDir "${DEST_DIR}"`;
try {
expect(() => {
execSync(command2, { stdio: 'inherit' });
} catch (error) {
fail(`Failed to execute command: ${error.message}`);
}
});
}).not.toThrow();
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 MiB