42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import cv2
|
|
import time
|
|
import numpy as np
|
|
|
|
def main():
|
|
cap = cv2.VideoCapture('/dev/video10')
|
|
frames, loopTime, initTime = 0, time.time(), time.time()
|
|
fps = 0
|
|
|
|
while True:
|
|
ret, frame = cap.read()
|
|
if not ret:
|
|
print("Failed to read frame")
|
|
break
|
|
|
|
# 检查帧数据是否需要重塑
|
|
if frame.size == 1280 * 720 * 3: # 检查是否为扁平化数据
|
|
frame = frame.reshape((720, 1280, 3)).astype(np.uint8)
|
|
else:
|
|
print(f"Unexpected frame shape: {frame.shape}")
|
|
|
|
# 显示帧
|
|
frames += 1
|
|
if frames % 30 == 0:
|
|
fps = 30 / (time.time() - loopTime)
|
|
print(f"30帧平均帧率: {fps:.2f} 帧")
|
|
loopTime = time.time()
|
|
|
|
cv2.putText(frame, f"FPS: {fps:.2f}", (10, 30),
|
|
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
|
cv2.imshow("MIPI Camera", frame)
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
break
|
|
|
|
print(f"总平均帧率: {frames / (time.time() - initTime):.2f}")
|
|
cap.release()
|
|
cv2.destroyAllWindows()
|
|
if __name__ == "__main__":
|
|
main()
|
|
|