
本文共 4477 字,大约阅读时间需要 14 分钟。
OpenCV������������������������������������������
������������������������������������������OpenCV���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������OpenCV������������������������������������������������������������������������������������������������������������
1. ������������������
OpenCV ��������� VideoCapture
���������������������������������������������������������������������
- ���������������������������������������������������������������
#include#include using namespace cv;using namespace std;int main(int argc, char** argv) { VideoCapture capture(0); if (!capture.isOpened()) { printf("could not open the camera...\n"); return -1; } namedWindow("frame", WINDOW_AUTOSIZE); Mat frame; while (true) { bool ret = capture.read(frame); if (!ret) break; imshow("frame", frame); char c = waitKey(50); if (c == 27) // ESC break; } return 0;}
- ���������������������������������������������������������������������������������
#include#include using namespace cv;using namespace std;int main(int argc, char** argv) { VideoCapture capture("C:/path/to/test.mp4"); if (!capture.isOpened()) { printf("could not open the video file...\n"); return -1; } namedWindow("frame", WINDOW_AUTOSIZE); Mat frame; while (true) { bool ret = capture.read(frame); if (!ret) break; imshow("frame", frame); char c = waitKey(50); if (c == 27) break; } return 0;}
- ������������������������������������������ URL ������������������������������
#include#include using namespace cv;using namespace std;int main(int argc, char** argv) { VideoCapture capture("http://example.com/video.mp4"); if (!capture.isOpened()) { printf("could not open the video...\n"); return -1; } namedWindow("frame", WINDOW_AUTOSIZE); Mat frame; while (true) { bool ret = capture.read(frame); if (!ret) break; imshow("frame", frame); char c = waitKey(50); if (c == 27) break; } return 0;}
2. ������������������
���������������������������������������������������������������OpenCV ������ VideoWriter
������������������������������
#include#include using namespace cv;using namespace std;int main(int argc, char** argv) { VideoCapture capture("C:/path/to/input.mp4"); if (!capture.isOpened()) { printf("could not open the video file...\n"); return -1; } namedWindow("frame", WINDOW_AUTOSIZE); Mat frame; VideoWriter writer("C:/path/to/output.mp4", capture.get(CAP_PROP_FOURCC), capture.get(CAP_PROP_FPS), Size(capture.get(CAP_PROP_FRAME_WIDTH), capture.get(CAP_PROP_FRAME_HEIGHT)), true); while (true) { bool ret = capture.read(frame); if (!ret) break; imshow("frame", frame); writer.write(frame); char c = waitKey(50); if (c == 27) break; } capture.release(); writer.release(); return 0;}
3. ������������������
���������������������������������������������������������������������������������������
CAP_PROP_FRAME_RATE
���������(Hz)CAP_PROP_FRAME_SIZE
������ x ���������CAP_PROP_FRAME_COUNT
������������������CAP_PROP_FOURCC
���������������������������FourCC���
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������
������������������������������������������������������������������������������������������������ 2GB ���������
������������������������������������������������������ FourCC ��������� YUV420p���������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������
��������������������������������� OpenCV ������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
