MCPcopy Create free account
hub / github.com/HyperInspire/InspireFace / read_binary_file_to_ndarray

Function read_binary_file_to_ndarray

python/test/test_utilis.py:95–114  ·  view source on GitHub ↗
(file_path, width, height)

Source from the content-addressed store, hash-verified

93
94
95def read_binary_file_to_ndarray(file_path, width, height):
96 nv21_size = width * height * 3 // 2 # NV21 size calculation
97
98 try:
99 with open(file_path, 'rb') as file:
100 file_data = file.read() # Read the entire file
101
102 if len(file_data) != nv21_size:
103 print(f"Expected file size is {nv21_size}, but got {len(file_data)}")
104 return None
105
106 # Assuming the file data is a complete NV21 frame
107 data = np.frombuffer(file_data, dtype=np.uint8)
108 return data
109 except FileNotFoundError:
110 print(f"File '{file_path}' not found.")
111 return None
112 except Exception as e:
113 print(f"An error occurred while reading the file: {str(e)}")
114 return None
115
116
117def print_benchmark_table(benchmark_results):

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected