Created
December 20, 2018 21:49
-
-
Save SubhiH/e9cdddca152716fd01bc7a9428773c3f to your computer and use it in GitHub Desktop.
Read streaming from camera and show RGB and Gray images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "opencv2/opencv.hpp" | |
| int main() { | |
| cv::VideoCapture cam(0); | |
| if (!cam.isOpened()) { | |
| throw std::runtime_error("Error"); | |
| } | |
| cv::namedWindow("Window"); | |
| while (true) { | |
| cv::Mat frame; | |
| cam >> frame; | |
| cv::resize(frame, frame, cv::Size(400, 400)); | |
| cv::imshow("bgr_frame", frame); | |
| cv::Mat gray_frame; | |
| cv::cvtColor(frame, gray_frame, CV_BGR2GRAY); | |
| cv::imshow("gray_frame", gray_frame); | |
| if (cv::waitKey(30) >= 0) break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment