58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#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;
|
|
} |