diff --git a/.gitignore b/.gitignore index 8db26c5..a2de652 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ logs/ public/snapshots/ # Aruco detection results -test/data/screenShots/*.json \ No newline at end of file +test/data/screenShots/*.json + +*_testResults/ \ No newline at end of file diff --git a/programs/__pycache__/readTwoImages.cpython-311.pyc b/programs/__pycache__/readTwoImages.cpython-311.pyc new file mode 100644 index 0000000..799ca2d Binary files /dev/null and b/programs/__pycache__/readTwoImages.cpython-311.pyc differ diff --git a/programs/readTwoImages.py b/programs/readTwoImages.py index 06e0958..4da1b31 100755 --- a/programs/readTwoImages.py +++ b/programs/readTwoImages.py @@ -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}'.") diff --git a/test/00_testSetup.json b/test/00_testSetup.json index 492e2a5..8819820 100644 --- a/test/00_testSetup.json +++ b/test/00_testSetup.json @@ -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" } ] } diff --git a/test/AA_readTwoImages.test.js b/test/AA_readTwoImages.test.js index 6e82ce8..3129a35 100644 --- a/test/AA_readTwoImages.test.js +++ b/test/AA_readTwoImages.test.js @@ -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}`); - } - }); -}); \ No newline at end of file + }).not.toThrow(); +}); + +}); diff --git a/test/data/screenShots/1779690911822_DSCF1382.JPG b/test/data/screenShots/1779690911822_DSCF1382.JPG new file mode 100644 index 0000000..1a322ec Binary files /dev/null and b/test/data/screenShots/1779690911822_DSCF1382.JPG differ diff --git a/test/data/screenShots/DSCF1379.JPG b/test/data/screenShots/DSCF1379.JPG new file mode 100644 index 0000000..ffe7586 Binary files /dev/null and b/test/data/screenShots/DSCF1379.JPG differ diff --git a/test/data/screenShots/DSCF1380.JPG b/test/data/screenShots/DSCF1380.JPG new file mode 100644 index 0000000..c6d5996 Binary files /dev/null and b/test/data/screenShots/DSCF1380.JPG differ diff --git a/test/data/screenShots/DSCF1381.JPG b/test/data/screenShots/DSCF1381.JPG new file mode 100644 index 0000000..60d9b95 Binary files /dev/null and b/test/data/screenShots/DSCF1381.JPG differ diff --git a/test/data/screenShots/DSCF1383.JPG b/test/data/screenShots/DSCF1383.JPG new file mode 100644 index 0000000..7ca0508 Binary files /dev/null and b/test/data/screenShots/DSCF1383.JPG differ