115 lines
3.6 KiB
Rust
115 lines
3.6 KiB
Rust
use anyhow::Result;
|
|
use opencv::{core, highgui, imgproc, prelude::*};
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
|
|
// Import modules from the project
|
|
use meteor_detect::display::{DisplayBackend, DisplayConfig, DisplayBackendType, create_optimal_display};
|
|
|
|
/// Simple display test to verify the display system works
|
|
fn main() -> Result<()> {
|
|
println!("=== Display System Test ===");
|
|
|
|
// Test 1: OpenCV Backend
|
|
println!("\n1. Testing OpenCV Backend...");
|
|
test_display_backend(DisplayBackendType::OpenCV)?;
|
|
|
|
// Test 2: GStreamer Backend
|
|
println!("\n2. Testing GStreamer Backend...");
|
|
test_display_backend(DisplayBackendType::GStreamer)?;
|
|
|
|
// Test 3: Auto-detection
|
|
println!("\n3. Testing Auto-detection...");
|
|
test_display_backend(DisplayBackendType::Auto)?;
|
|
|
|
println!("\n=== All tests completed! ===");
|
|
Ok(())
|
|
}
|
|
|
|
fn test_display_backend(backend_type: DisplayBackendType) -> Result<()> {
|
|
let display_config = DisplayConfig {
|
|
display_scale: 1.0,
|
|
frame_skip: 1,
|
|
async_rendering: false,
|
|
max_render_time_ms: 33,
|
|
};
|
|
|
|
println!("Creating display backend...");
|
|
let mut display = create_optimal_display(display_config, backend_type);
|
|
|
|
// Check which backend was selected
|
|
let stats = display.get_stats();
|
|
println!("Selected backend: {}", stats.backend_name);
|
|
|
|
let window_name = "Display Test";
|
|
println!("Creating window: {}", window_name);
|
|
display.create_window(window_name)?;
|
|
|
|
// Create a simple test image
|
|
let mut test_image = core::Mat::zeros(480, 640, core::CV_8UC3)?.to_mat()?;
|
|
|
|
// Draw some test patterns
|
|
for i in 0..10 {
|
|
// Clear the image
|
|
test_image.set_scalar(core::Scalar::new(0.0, 0.0, 0.0, 0.0))?;
|
|
|
|
// Draw a moving circle
|
|
let center = core::Point::new(320 + (i as f32 * 10.0).sin() as i32 * 100, 240);
|
|
let color = core::Scalar::new(
|
|
(i as f64 * 25.0) % 255.0,
|
|
((i + 3) as f64 * 25.0) % 255.0,
|
|
((i + 6) as f64 * 25.0) % 255.0,
|
|
0.0
|
|
);
|
|
|
|
imgproc::circle(&mut test_image, center, 50, color, -1, imgproc::LINE_8, 0)?;
|
|
|
|
// Add text
|
|
let text = format!("Frame {} - Backend: {}", i + 1, stats.backend_name);
|
|
imgproc::put_text(
|
|
&mut test_image,
|
|
&text,
|
|
core::Point::new(10, 30),
|
|
imgproc::FONT_HERSHEY_SIMPLEX,
|
|
0.7,
|
|
core::Scalar::new(255.0, 255.0, 255.0, 0.0),
|
|
2,
|
|
imgproc::LINE_AA,
|
|
false,
|
|
)?;
|
|
|
|
// Display frame
|
|
println!("Displaying frame {}...", i + 1);
|
|
match display.show_frame(window_name, &test_image) {
|
|
Ok(_) => println!("Frame {} displayed successfully", i + 1),
|
|
Err(e) => {
|
|
println!("Error displaying frame {}: {}", i + 1, e);
|
|
return Err(e);
|
|
}
|
|
}
|
|
|
|
// Check for key press
|
|
let key = display.poll_key(100)?;
|
|
if key == 27 { // ESC key
|
|
println!("ESC pressed, stopping test");
|
|
break;
|
|
}
|
|
|
|
// Small delay
|
|
thread::sleep(Duration::from_millis(200));
|
|
}
|
|
|
|
// Clean up
|
|
display.destroy_window(window_name)?;
|
|
|
|
// Show final stats
|
|
let final_stats = display.get_stats();
|
|
println!("Final stats for {}: {} frames displayed, {} dropped, avg render time: {:.2}ms",
|
|
final_stats.backend_name,
|
|
final_stats.frames_displayed,
|
|
final_stats.frames_dropped,
|
|
final_stats.avg_render_time_ms);
|
|
|
|
println!("Test completed successfully!");
|
|
Ok(())
|
|
} |