HDMI输入直至Yolov5识别全流程代码

This commit is contained in:
zhangpeng
2025-04-28 14:48:28 +08:00
commit 31940162fc
112 changed files with 222134 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import cv2
import numpy as np
cap = cv2.VideoCapture('/dev/video0', cv2.CAP_V4L2)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('B', 'G', 'R', '3'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
ret, frame = cap.read()
if ret:
print(f"Captured frame shape: {frame.shape}")
# 解决形状问题reshape frames to (720, 1280, 3)
frame = frame.reshape((720, 1280, 3)) # ensure the correct shape if frame is 1D
# 确保数据是有效的8位无符号整型
if frame.dtype != np.uint8:
frame = frame.astype(np.uint8)
# 输出调试信息
print(f"Frame dtype: {frame.dtype}, Frame shape after reshape: {frame.shape}")
# 尝试保存为JPEG
cv2.imwrite("hdmi_frame.jpg", frame)
print("Frame saved as JPEG")
# 可选保存RAW数据
with open("hdmi_frame.raw", "wb") as f:
f.write(frame.tobytes())
print("RAW data saved")
else:
print("Capture failed")
cap.release()

View File

@@ -0,0 +1,24 @@
cap = cv2.VideoCapture('/dev/video10')
frames, loopTime, initTime = 0, time.time(), time.time()
fps = 0
while True:
frames += 1
ret, frame = cap.read()
if not ret:
break
# 现在应该可以直接使用frame不需要reshape
if frames % 30 == 0:
print("30帧平均帧率:\t", 30 / (time.time() - loopTime), "")
fps = 30 / (time.time() - loopTime)
loopTime = time.time()
cv2.putText(frame, "FPS: {:.2f}".format(fps), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.imshow("MIPI Camera", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()