6주차 수업 끝
This commit is contained in:
58
ch04/Video/main.cpp
Normal file
58
ch04/Video/main.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
int camera_in();
|
||||
int camera_in_video_out();
|
||||
|
||||
int main() {
|
||||
return camera_in_video_out();
|
||||
}
|
||||
|
||||
int camera_in() {
|
||||
cv::VideoCapture camera(0);
|
||||
if (!camera.isOpened()) {
|
||||
std::cerr << "camera.isopened()" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
cv::Mat img;
|
||||
double fps = 1000 / camera.get(cv::VideoCaptureProperties::CAP_PROP_FPS);
|
||||
std::cout << "\n\n" << fps << "\n\n";
|
||||
while (true) {
|
||||
camera >> img;
|
||||
if (img.empty()) {
|
||||
std::cerr << "img.empty()" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
cv::imshow("img", img);
|
||||
if (cv::waitKey(fps) == 27)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int camera_in_video_out() {
|
||||
cv::VideoCapture camera(0);
|
||||
if (!camera.isOpened()) {
|
||||
std::cerr << "camera.isopened()" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
cv::Mat img;
|
||||
int w = cvRound(camera.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_WIDTH));
|
||||
int h = cvRound(camera.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_HEIGHT));
|
||||
double fps = camera.get(cv::VideoCaptureProperties::CAP_PROP_FPS);
|
||||
|
||||
cv::VideoWriter outputVideo("output.avi", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), fps, cv::Size(w, h));
|
||||
|
||||
while (true) {
|
||||
camera >> img;
|
||||
if (img.empty()) {
|
||||
std::cerr << "img.empty()" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
outputVideo << ~img;
|
||||
cv::imshow("img", img);
|
||||
if (cv::waitKey(fps) == 27)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user