Skip to content

Instantly share code, notes, and snippets.

@SubhiH
Created December 20, 2018 21:49
Show Gist options
  • Select an option

  • Save SubhiH/e9cdddca152716fd01bc7a9428773c3f to your computer and use it in GitHub Desktop.

Select an option

Save SubhiH/e9cdddca152716fd01bc7a9428773c3f to your computer and use it in GitHub Desktop.
Read streaming from camera and show RGB and Gray images
#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