read frame code
parent
dcbd70c391
commit
e7e36aec1e
|
@ -45,10 +45,37 @@ imgshow大约花费3.5ms(单帧图像imgshow的操作)
|
|||
|
||||
使用python opencv读取一段视频,仅进行读取,消耗时间在25ms左右。
|
||||
|
||||
```
|
||||
while True:
|
||||
frame_time = time.time()
|
||||
ret, frame = cap.read()
|
||||
|
||||
if not ret:
|
||||
print("End of video or failed to read frame.")
|
||||
break
|
||||
# 显示当前帧
|
||||
cv2.imshow("Video Playback", frame)
|
||||
frame_time = time.time() - frame_time
|
||||
print(f"frame cost: {1000*frame_time:.2f} ms")
|
||||
```
|
||||
|
||||
![1](./image/1.jpg)
|
||||
|
||||
使用c++ opencv读取一段时间,仅进行读取,消耗时间在30ms左右,但也有40ms+和50ms+以及10ms的情况,不太稳定。
|
||||
|
||||
```
|
||||
while (true) {
|
||||
int64 t = getTickCount();
|
||||
// 读取视频帧
|
||||
cap >> frame;
|
||||
// // 显示当前帧
|
||||
// cv::imshow("Video Playback", frame);
|
||||
int64 t1 = getTickCount()-t;
|
||||
std::cout << frame_num << " frame cost:"<< t1*1000/cv::getTickFrequency()<< "ms" << std::endl;
|
||||
frame_num++;
|
||||
}
|
||||
```
|
||||
|
||||
![2](./image/2.jpg)
|
||||
|
||||
c++不添加指定帧率(cap.set(cv::CAP_PROP_FPS, 30)),读取帧率速度花费时间会很长,不添加指定帧率的情况下读取一帧需要200ms。
|
||||
|
|
Loading…
Reference in New Issue