5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenCV3で画像キャプチャしてウインドウ表示するだけ

Posted at
camcap.cpp
# include <iostream>
# include <opencv2/opencv.hpp>

int main()
{
    const char * const window = "Capture (Press ESC to exit)";
    const double scale = 0.75;
    const int delay = 32;   // [msec]

    cv::VideoCapture cap(0);
    if (!cap.isOpened()) {
        std::cerr << "fail to open cv::VideoCapture" << std::endl;
        return 2; 
    }

    const double width = cap.get(cv::CAP_PROP_FRAME_WIDTH) * scale;
    const double height = cap.get(cv::CAP_PROP_FRAME_HEIGHT) * scale;
    cap.set(cv::CAP_PROP_FRAME_WIDTH, width);
    cap.set(cv::CAP_PROP_FRAME_HEIGHT, height);
    std::cout << "frame=" << width << 'x' << height << std::endl;

    cv::namedWindow(window);
    cv::Mat frame;
    do {
        cap >> frame;
        cv::imshow(window, frame);
    } while (cv::waitKey(delay) != '\x1b');

    return 0;
}
$ brew install science/opencv3
...
$ clang++ -std=c++14 -W -Wall -O2 -o camcap camcap.cpp -I/usr/local/opt/opencv3/include -L/usr/local/opt/opencv3/lib -lopencv_core -lopencv_highgui -lopencv_videoio
$ ./camcap
5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?