Skip to content

Instantly share code, notes, and snippets.

@KeitetsuWorks
Last active May 29, 2018 14:57
Show Gist options
  • Save KeitetsuWorks/05a4efa76b7caa28de42e90bd0462282 to your computer and use it in GitHub Desktop.
Save KeitetsuWorks/05a4efa76b7caa28de42e90bd0462282 to your computer and use it in GitHub Desktop.
/**
* @file opencv_camera.cpp
* @brief OpenCV Camera Capture Program
* @author Keitetsu
* @date 2018/02/24
* @copyright Copyright (c) 2018 Keitetsu
* @par License
* This software is released under the MIT License.
*/
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int argc, const char* argv[])
{
cv::VideoCapture cap;
cap.open(0);
if (!cap.isOpened()) {
std::cerr << "Failed to open camera device." << std::endl;
return -1;
}
while (1) {
cv::Mat frame;
if (!cap.read(frame)) {
std::cerr << "Failed to capture a frame." << std::endl;
break;
}
cv::imshow("camera", frame);
int key;
key = cv::waitKey(1);
if (key == 27) {
break;
}
}
cv::destroyAllWindows();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment