File size: 2,011 Bytes
06417df
 
 
 
 
 
f4c30f7
06417df
 
 
 
 
 
 
 
 
f4c30f7
 
 
06417df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4c30f7
06417df
 
 
 
 
 
 
 
f4c30f7
06417df
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Create sample images to demonstrate lane detection
"""
import cv2
import numpy as np
import os
import tempfile


def create_sample_frames():
    """Create and save sample frames showing lane detection"""
    
    # First, create a test video and process it
    from create_test_video import create_test_video
    from lane_detection import process_video
    
    temp_dir = tempfile.gettempdir()
    input_video = os.path.join(temp_dir, "demo_input.mp4")
    output_video = os.path.join(temp_dir, "demo_output.mp4")
    
    # Create a test video with clear lanes
    print("Creating demo video...")
    create_test_video(input_video, duration_sec=2, fps=15)
    
    print("Processing video with lane detection...")
    success = process_video(input_video, output_video)
    
    if not success:
        print("Failed to process video")
        return
    
    # Extract a sample frame from the output
    cap = cv2.VideoCapture(output_video)
    
    # Get a frame from the middle of the video
    total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    middle_frame = total_frames // 2
    
    cap.set(cv2.CAP_PROP_POS_FRAMES, middle_frame)
    ret, frame = cap.read()
    
    if ret:
        # Save the frame
        output_path = os.path.join(temp_dir, "lane_detection_demo.png")
        cv2.imwrite(output_path, frame)
        print(f"✓ Sample frame saved to: {output_path}")
        print(f"  Frame shows original (left) and lane detection (right)")
        
        # Also create a smaller version for documentation
        height, width = frame.shape[:2]
        scale = 0.5
        small_frame = cv2.resize(frame, (int(width * scale), int(height * scale)))
        small_output_path = os.path.join(temp_dir, "lane_detection_demo_small.png")
        cv2.imwrite(small_output_path, small_frame)
        print(f"✓ Smaller version saved to: {small_output_path}")
    else:
        print("Failed to extract frame")
    
    cap.release()


if __name__ == "__main__":
    create_sample_frames()