코드:
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
|
#include <iostream>
using namespace std;
using namespace cv;
int main() {
VideoCapture cap; //카메라 또는 비디오 파일로 부터 프레임을 읽는데 필요한 정보
if (!cap.isOpened()) {
return -1;
}
namedWindow("Video");
Mat frame;
while (1) {
break;
imshow("Video", frame);
if (waitKey(1000 / fps) >= 0) break; //키보드 입력으로 재생을 멈추고자 할 때
}
cap.release(); return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
|
|
실행결과:
설명:
VideoCapture cap;
if (!cap.isOpened()) {
return -1;
}
avi파일을 가져와서 open.
namedWindow("Video");
윈도우창 이름 설정
Mat frame;
int fps = (int)cap.get(CAP_PROP_FPS); //초당 프레임 수
while (1) {
if (!cap.read(frame)) //파일 끝에 도달하면 false 반환
break;
imshow("Video", frame);
if (waitKey(1000 / fps) >= 0) break; //키보드 입력으로 재생을 멈추고자 할 때
}
cap.release(); return 0;
비디오 보여주는 코드
1000을 초당 프레임 수로 나누면 기본 속도로 재생이 되고 1000에서 줄이거나 늘려서 재생속도를 조절할 수 있다.
'C,C++ > Opencv, c++' 카테고리의 다른 글
Opencv, c++, threshold() (0) | 2019.10.04 |
---|---|
Opencv, c++, cvtColor(), split(), merge() (0) | 2019.10.04 |
Opencv, c++, imshow, imwrite (0) | 2019.10.04 |
Opencv, c++, Rectangle 출력 (0) | 2019.09.22 |