File size: 2,678 Bytes
178f61f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
import h5py
import numpy as np
import cv2
import os

def verify_h5(file_path):
    if not os.path.exists(file_path):
        print(f"File not found: {file_path}")
        return

    with h5py.File(file_path, 'r') as f:
        print(f"Keys: {list(f.keys())}")
        for key in f.keys():
            print(f"{key} shape: {f[key].shape}")
        
        num_samples = f['left_patches'].shape[0]
        if num_samples == 0:
            print("No samples found.")
            return
            
        # Display a few samples
        for i in range(min(num_samples, 5)):
            lp = f['left_patches'][i] # (4, 8, 8)
            rp = f['right_patches'][i] # (4, 8, 8)
            lg = f['left_gaze'][i]
            rg = f['right_gaze'][i]
            
            # Combine patches into a 16x16 or 32x8 image
            # 4 patches of 8x8 -> 16x16
            l_combined = np.zeros((16, 16), dtype='uint8')
            l_combined[0:8, 0:8] = lp[0]
            l_combined[0:8, 8:16] = lp[1]
            l_combined[8:16, 0:8] = lp[2]
            l_combined[8:16, 8:16] = lp[3]
            
            r_combined = np.zeros((16, 16), dtype='uint8')
            r_combined[0:8, 0:8] = rp[0]
            r_combined[0:8, 8:16] = rp[1]
            r_combined[8:16, 0:8] = rp[2]
            r_combined[8:16, 8:16] = rp[3]
            
            # Upscale for better viewing
            l_view = cv2.resize(l_combined, (128, 128), interpolation=cv2.INTER_NEAREST)
            r_view = cv2.resize(r_combined, (128, 128), interpolation=cv2.INTER_NEAREST)
            
            # Create a black board to show info
            info = np.zeros((128, 400), dtype='uint8')
            cv2.putText(info, f"Sample {i}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.7, 255, 2)
            cv2.putText(info, f"L Gaze: {lg[0]:.3f}, {lg[1]:.3f}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.6, 255, 1)
            cv2.putText(info, f"R Gaze: {rg[0]:.3f}, {rg[1]:.3f}", (10, 90), cv2.FONT_HERSHEY_SIMPLEX, 0.6, 255, 1)
            
            combined = np.hstack([l_view, r_view, info])
            output_dir = 'data/verification'
            os.makedirs(output_dir, exist_ok=True)
            output_path = os.path.join(output_dir, f"sample_{i}.png")
            cv2.imwrite(output_path, combined)
            print(f"Saved verification image to {output_path}")
            print(f"Sample {i}: Left Gaze {lg}, Right Gaze {rg}")
                
    # cv2.destroyAllWindows()

if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--file', type=str, default='data/processed/p00.h5')
    args = parser.parse_args()
    verify_h5(args.file)