#!/usr/bin/env python3 """ Simple test script to verify panel splitting functionality Tests the panel splitting with 6786505.jpg (horizontal strip layout) """ import sys import os import cv2 import numpy as np from pathlib import Path from panel_splitter import PanelSplitter def test_simple_splitting(): """Test splitting without OpenAI guidance""" print("=" * 60) print("TESTING SIMPLE PANEL SPLITTING") print("=" * 60) # Initialize splitter with debug mode splitter = PanelSplitter(debug=True) # Target layout file - this is a horizontal strip with many panels layout_path = Path("layouts") / "6786505.jpg" if not layout_path.exists(): print(f"โŒ ERROR: Layout file {layout_path} not found!") return False print(f"๐Ÿ“ Testing with: {layout_path.name}") # Load and examine the image image = cv2.imread(str(layout_path)) if image is None: print(f"โŒ ERROR: Could not load image {layout_path}") return False height, width = image.shape[:2] print(f"๐Ÿ“ Image dimensions: {width}x{height}") # Test with different target counts test_counts = [5, 8, 10, 12] for target_count in test_counts: print(f"\n๐ŸŽฏ Testing with target count: {target_count}") print("โ”€" * 40) # Split the layout splits = splitter.split_panels(str(layout_path), target_count) print(f"Generated {len(splits)} splits") if len(splits) > 0: print("โœ… Successfully generated splits!") # Save split images splits_dir = Path("test_splits") splits_dir.mkdir(exist_ok=True) for i, split in enumerate(splits): split_filename = splits_dir / f"6786505_target{target_count}_split_{i+1:02d}.jpg" cv2.imwrite(str(split_filename), split['image']) print(f" Saved {len(splits)} split images to test_splits/") # Show split details for i, split in enumerate(splits): x, y, w, h = split['bounds'] print(f" Split {i+1:2d}: [{x:4d}, {y:4d}, {w:4d}, {h:4d}] conf={split['confidence']:.3f}") else: print("โŒ No splits generated") print("\n" + "=" * 60) print("๐ŸŽ‰ SIMPLE SPLITTING TEST COMPLETED!") print("Check the test_splits/ directory for generated images.") print("=" * 60) return True def test_individual_methods(): """Test individual splitting methods""" print("\n" + "=" * 60) print("TESTING INDIVIDUAL SPLITTING METHODS") print("=" * 60) splitter = PanelSplitter(debug=True) layout_path = Path("layouts") / "6786505.jpg" image = cv2.imread(str(layout_path)) if image is None: print("โŒ Could not load image") return False target_count = 8 methods = [ splitter._enhanced_gradient_analysis, splitter._advanced_canny_detection, splitter._template_matching_method, splitter._contour_analysis_method, splitter._texture_analysis_method, splitter._clustering_method ] for method in methods: print(f"\n๐Ÿ”ฌ Testing {method.__name__}...") try: result = method(image, target_count) if result: print(f" โœ… Generated {len(result)} boundaries") for i, boundary in enumerate(result): bounds = boundary['bounds'] print(f" {i+1}: [{bounds[0]:4d}, {bounds[1]:4d}, {bounds[2]:4d}, {bounds[3]:4d}] conf={boundary['confidence']:.3f}") else: print(" โŒ No boundaries generated") except Exception as e: print(f" โŒ Error: {e}") return True def main(): """Main test function""" print("๐Ÿงช STARTING SIMPLE PANEL SPLITTING TEST") # Test basic splitting simple_success = test_simple_splitting() # Test individual methods methods_success = test_individual_methods() print(f"\n๐Ÿ“Š FINAL RESULTS:") print(f"Simple splitting: {'โœ… PASSED' if simple_success else 'โŒ FAILED'}") print(f"Individual methods: {'โœ… PASSED' if methods_success else 'โŒ FAILED'}") if simple_success and methods_success: print("\n๐ŸŽ‰ ALL TESTS PASSED! The panel splitting is working correctly.") return 0 else: print("\nโŒ Some tests failed. Please check the output above.") return 1 if __name__ == "__main__": sys.exit(main())