Help us understand the problem. What is going on with this article?

OpenCV4.0をソースでUbuntu18.04にビルドし、C++でwebcameraのライブ映像をウィンドウに表示まで

OpenCV4.0をインストール

こちら(記事1)を参考にインストールしましたが、こちらにあるCMakeのオプションではビデオ系が入れられないので、いろいろいじる。

まず、dependency
こちらの記事の、Step2 のInstall dependenciesを、とりあえずすべて入れた(どれがどれだか今はよくわからない。)

記事1を参考に自分で書いたシェルスクリプトはこちら。

opencv4.0_build-ubuntu18.04_02.sh
#!/bin/bash

SOURCE_DIR="echo $(cd $(dirname $0);pwd)"
BUILD_DIR=${SOURCE_DIR}/build
GENERATOR_NAME="Unix Makefiles"

mkdir build
cd build

cmake \
-G "${GENERATOR_NAME}" \
--build ${BUILD_DIR} \
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_JPEG=ON \
-D BUILD_PACKAGE=ON \
-D BUILD_PNG=ON \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_TESTS=ON \
-D BUILD_TIFF=ON \
-D BUILD_WITH_DEBUG_INFO=ON \
-D BUILD_ZLIB=OFF \
-D BUILD_opencv_apps=ON \
-D BUILD_opencv_calib3d=ON \
-D BUILD_opencv_core=ON \
-D BUILD_opencv_features2d=ON \
-D BUILD_opencv_flann=ON \
-D BUILD_opencv_highgui=ON \
-D BUILD_opencv_imgcodecs=ON \
-D BUILD_opencv_imgproc=ON \
-D BUILD_opencv_java=ON \
-D BUILD_opencv_ml=ON \
-D BUILD_opencv_objdetect=ON \
-D BUILD_opencv_photo=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_shape=ON \
-D BUILD_opencv_stitching=ON \
-D BUILD_opencv_superres=ON \
-D BUILD_opencv_ts=ON \
-D BUILD_opencv_video=ON \
-D BUILD_opencv_videoio=ON \
-D BUILD_opencv_videostab=ON \
-D BUILD_opencv_viz=ON \
-D BUILD_opencv_world=ON \
-D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_1394=ON \
-D WITH_CUBLAS=OFF \
-D WITH_FFMPEG=ON \
-D WITH_GDAL=OFF \
-D WITH_GPHOTO2=ON \
-D WITH_GIGEAPI=ON \
-D WITH_GSTREAMER=ON \
-D WITH_GTK=ON \
-D WITH_INTELPERC=OFF \
-D WITH_IPP=ON \
-D WITH_IPP_A=OFF \
-D WITH_JPEG=ON \
-D WITH_LIBV4L=OFF \
-D WITH_OPENCL=ON \
-D WITH_OPENCLAMDBLAS=OFF \
-D WITH_OPENCLAMDFFT=OFF \
-D WITH_OPENCL_SVM=ON \
-D WITH_OPENEXR=OFF \
-D WITH_OPENGL=ON \
-D WITH_OPENMP=OFF \
-D WITH_OPENNI=OFF \
-D WITH_PNG=ON \
-D WITH_PTHREADS_PF=OFF \
-D WITH_PVAPI=ON \
-D WITH_QT=OFF \
-D WITH_TBB=ON \
-D WITH_TIFF=ON \
-D WITH_UNICAP=OFF \
-D WITH_V4L=OFF \
-D WITH_VTK=OFF \
-D WITH_XIMEA=OFF \
-D WITH_XINE=OFF \
${SOURCE_DIR}

で、後は記事1に同じ。

webcameraのライブ映像をウィンドウに表示

映像を表示するだけのコードはこちら。(フレームレートのみ、指定)

captureimg.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc.hpp>

using namespace std;

int main(int argh, char* argv[]){
        cv::VideoCapture cap(2);

        if(!cap.isOpened()){
                return -1;
        }

        cap.set(cv::CAP_PROP_FPS, 30);
        cout << cap.get(cv::CAP_PROP_FPS) << endl;

        cv::Mat frame;
        while(cap.read(frame))
        {

                cv::imshow("win", frame);
                const int key = cv::waitKey(1);
                if(key == 'q' /*113*/)
                {
                        break;
                }
                else if(key == 's'/*115*/) // when pressed s
                {
                        cv::imwrite("img.png", frame);
                }
        }
        cv::destroyAllWindows();
        return 0;
}

他の値をいじりたいときはこちらを参考に。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした