OpenCVとyaml-cppをCLionで動かしたかった
環境
- Windows7
- Cygwin(64bit)
- CLion CL-140.569.17
- OpenCV 2.4.10
- yaml-cpp 0.5.1
OpenCVのビルド
↓を参考にした
http://hvrl.ics.keio.ac.jp/kimura/opencv/opencv-2.4.10.html.ja
ffmpeg, VTKは使わないのでスキップ
apt-cyg install \
unzip \
cmake \
gcc-g++ \
make \
patch \
libIlmImf-devel \
libjasper-devel \
libjpeg-devel \
libpng-devel \
libtiff-devel \
libhdf5-devel \
libbz2-devel \
zlib-devel
git clone https://github.com/Itseez/opencv.git
git checkout 2.4.10
wget http://hvrl.ics.keio.ac.jp/kimura/opencv/files/opencv-2.4.10-cygwin-patch-20141008.txt.gz
gunzip opencv-2.4.10-cygwin-patch-20141008.txt.gz
patch -p1 < opencv-2.4.10-cygwin-patch-20141008.txt
mkdir build
cd build
cmake \
-D CMAKE_LEGACY_CYGWIN_WIN32=0 \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_SHARED_LIBS=ON \
..
make
make install
yaml-cppのビルド
apt-cyg install libboost-devel
wget https://yaml-cpp.googlecode.com/files/yaml-cpp-0.5.1.tar.gz
tar zxvf yaml-cpp-0.5.1.tar.gz
cd yaml-cpp-0.5.1
mkdir build
cd build
cmake ..
make
PATHの設定
Cygwin
export PATH=$PATH:/usr/local/opencv2.4.10/bin/:/cygdrive/c/cygwin64/bin/
Windows
C:\cygwin64\bin
C:\cygwin64\usr\local\opencv2.4.10\bin
apt-cyg install libboost-devel
wget https://yaml-cpp.googlecode.com/files/yaml-cpp-0.5.1.tar.gz
tar zxvf yaml-cpp-0.5.1.tar.gz
cd yaml-cpp-0.5.1
mkdir build
cd build
cmake ..
make
Cygwin
export PATH=$PATH:/usr/local/opencv2.4.10/bin/:/cygdrive/c/cygwin64/bin/
Windows
C:\cygwin64\bin
C:\cygwin64\usr\local\opencv2.4.10\bin
Pathに↑を追加
サンプルコード
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(sample)
set(YAML_CPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/lib/yaml-cpp-0.5.1)
find_package(OpenCV REQUIRED)
include_directories(${YAML_CPP_ROOT}/include)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES source/main.cpp)
add_executable(sample ${SOURCE_FILES})
target_link_libraries(sample
${OpenCV_LIBS}
${YAML_CPP_ROOT}/build/libyaml-cpp.a
)
main.cpp
#include <iostream>
#include <opencv2/opencv.hpp>
#include <yaml-cpp/yaml.h>
int main() {
YAML::Node config = YAML::LoadFile("config.yml");
std::string filename = config["filename"].as<std::string>();
cv::Mat image = cv::imread(filename);
cv::imwrite("./output.bmp", image);
return 0;
}
config.yml
filename: lenna.bmp
メモ
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(sample)
set(YAML_CPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/lib/yaml-cpp-0.5.1)
find_package(OpenCV REQUIRED)
include_directories(${YAML_CPP_ROOT}/include)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES source/main.cpp)
add_executable(sample ${SOURCE_FILES})
target_link_libraries(sample
${OpenCV_LIBS}
${YAML_CPP_ROOT}/build/libyaml-cpp.a
)
main.cpp
#include <iostream>
#include <opencv2/opencv.hpp>
#include <yaml-cpp/yaml.h>
int main() {
YAML::Node config = YAML::LoadFile("config.yml");
std::string filename = config["filename"].as<std::string>();
cv::Mat image = cv::imread(filename);
cv::imwrite("./output.bmp", image);
return 0;
}
config.yml
filename: lenna.bmp
ビルドはCLion上から可能
コマンドプロンプトとCygwin上からは実行できたが、CLion上から実行すると
ExecutionException: During startup program exited with code 0xc0000135.
上記エラーが出て実行できなかった
Author And Source
この問題について(OpenCVとyaml-cppをCLionで動かしたかった), 我々は、より多くの情報をここで見つけました https://qiita.com/_flet/items/50fc9f45f538f5657c78著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .