質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CMake

CMakeはクロスプラットフォームで作動するオープンソースのビルドシステムです。コマンドライン又は組み込まれた開発環境で使うことができる元のmakefileとプロジェクトファイルを生成します。

GitHub Pages

GitHub Pagesは、GitHubが提供するホスティングサービス。ブログやプロジェクトのWebページをGit/GitHubのリポジトリを用いて簡単に公開できます。静的Webページのためのホスティングサービスで、GitHubのアカウントがあれば無料での利用が可能です。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

1回答

779閲覧

GitHubに掲載されているC++プログラムを実行したい

nsan_goodjob

総合スコア1

CMake

CMakeはクロスプラットフォームで作動するオープンソースのビルドシステムです。コマンドライン又は組み込まれた開発環境で使うことができる元のmakefileとプロジェクトファイルを生成します。

GitHub Pages

GitHub Pagesは、GitHubが提供するホスティングサービス。ブログやプロジェクトのWebページをGit/GitHubのリポジトリを用いて簡単に公開できます。静的Webページのためのホスティングサービスで、GitHubのアカウントがあれば無料での利用が可能です。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2023/02/01 16:53

実現したいこと

以下のページで公開されているプログラムを実行したいです。
https://github.com/davidstutz/superpixel-benchmark

自分が行っている方法以外に実行するための環境やエラーの原因をご存じの方いましたら教えていただきたいです。

前提

やってみたいことができそうなプログラムをGitHubで見つけたのですが、どのような環境が必要で、どのようにこのプログラムを実行させるのかわかりません。

上記のページのプログラムをダウンロードし、vscodeやvisualstudioで実行しようと試みましたが、以下のようなエラーが出てしまいます。

実行するための環境やエラーの原因をご存じの方いましたら教えていただきたいです。

また、CMakeList.txtがある場合、CMakeでビルドしなければいけないのかなども不明です。

発生している問題・エラーメッセージ

ソース ファイルを開けません "opencv2/opencv_modules.hpp" (dependency of "C:\Users\〇〇\AppData\Local\Microsoft\vscode-cpptools\ipch\b163e7505d9cd06f\opencv2\opencv.hpp") [{ "resource": "/c:/Users/○○/SuperPixcel/superpixel-benchmark-master/ccs_cli/main.cpp", "owner": "cpptools", "severity": 8, "message": "opencv2/opencv.hpp: No such file or directory", "source": "gcc", "startLineNumber": 33, "startColumn": 10, "endLineNumber": 33, "endColumn": 10 }] opencv2/opencv.hpp: No such file or directory

該当のソースコード

C++

1/** 2 * Copyright (c) 2016, David Stutz 3 * Contact: david.stutz@rwth-aachen.de, davidstutz.de 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without modification, 7 * are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * 3. Neither the name of the copyright holder nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <fstream> 33#include <opencv2/opencv.hpp> 34#include <boost/filesystem.hpp> 35#include <boost/program_options.hpp> 36#include <boost/timer.hpp> 37#include "ccs_opencv.h" 38#include "io_util.h" 39#include "superpixel_tools.h" 40#include "visualization.h" 41 42/** \brief Command line tool for running CCS. 43 * Usage: 44 * \code{sh} 45 * $ ../bin/ccs_cli --help 46 * Allowed options: 47 * -h [ --help ] produce help message 48 * -i [ --input ] arg the folder to process 49 * -s [ --superpixels ] arg (=400) number of superpixels 50 * -c [ --compactness ] arg (=500) compactness weight 51 * -t [ --iterations ] arg (=20) number of iterations to perform 52 * -r [ --color-space ] arg (=0) 0 = RGB, >0 = Lab 53 * -o [ --csv ] arg save segmentation as CSV file 54 * -v [ --vis ] arg visualize contours 55 * -x [ --prefix ] arg output file prefix 56 * -w [ --wordy ] verbose/wordy/debug 57 * \endcode 58 * \author David Stutz 59 */ 60int main(int argc, const char** argv) { 61 62 boost::program_options::options_description desc("Allowed options"); 63 desc.add_options() 64 ("help,h", "produce help message") 65 ("input,i", boost::program_options::value<std::string>(), "the folder to process") 66 ("superpixels,s", boost::program_options::value<int>()->default_value(400), "number of superpixels") 67 ("compactness,c", boost::program_options::value<int>()->default_value(500), "compactness weight") 68 ("iterations,t", boost::program_options::value<int>()->default_value(20), "number of iterations to perform") 69 ("color-space,r", boost::program_options::value<int>()->default_value(0), "0 = RGB, >0 = Lab") 70 ("csv,o", boost::program_options::value<std::string>()->default_value(""), "save segmentation as CSV file") 71 ("vis,v", boost::program_options::value<std::string>()->default_value(""), "visualize contours") 72 ("prefix,x", boost::program_options::value<std::string>()->default_value(""), "output file prefix") 73 ("wordy,w", "verbose/wordy/debug"); 74 75 boost::program_options::positional_options_description positionals; 76 positionals.add("input", 1); 77 78 boost::program_options::variables_map parameters; 79 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).positional(positionals).run(), parameters); 80 boost::program_options::notify(parameters); 81 82 if (parameters.find("help") != parameters.end()) { 83 std::cout << desc << std::endl; 84 return 1; 85 } 86 87 boost::filesystem::path output_dir(parameters["csv"].as<std::string>()); 88 if (!output_dir.empty()) { 89 if (!boost::filesystem::is_directory(output_dir)) { 90 boost::filesystem::create_directories(output_dir); 91 } 92 } 93 94 boost::filesystem::path vis_dir(parameters["vis"].as<std::string>()); 95 if (!vis_dir.empty()) { 96 if (!boost::filesystem::is_directory(vis_dir)) { 97 boost::filesystem::create_directories(vis_dir); 98 } 99 } 100 101 boost::filesystem::path input_dir(parameters["input"].as<std::string>()); 102 if (!boost::filesystem::is_directory(input_dir)) { 103 std::cout << "Image directory not found ..." << std::endl; 104 return 1; 105 } 106 107 std::string prefix = parameters["prefix"].as<std::string>(); 108 109 bool wordy = false; 110 if (parameters.find("wordy") != parameters.end()) { 111 wordy = true; 112 } 113 114 int superpixels = parameters["superpixels"].as<int>(); 115 int compactness = parameters["compactness"].as<int>(); 116 int iterations = parameters["iterations"].as<int>(); 117 int color_space_int = parameters["color-space"].as<int>(); 118 119 bool lab = false; 120 if (color_space_int > 0) { 121 lab = true; 122 } 123 124 std::multimap<std::string, boost::filesystem::path> images; 125 std::vector<std::string> extensions; 126 IOUtil::getImageExtensions(extensions); 127 IOUtil::readDirectory(input_dir, extensions, images); 128 129 float total = 0; 130 for(std::multimap<std::string, boost::filesystem::path>::iterator it = images.begin(); 131 it != images.end(); ++it) { 132 133 cv::Mat image = cv::imread(it->first); 134 cv::Mat labels; 135 136 int region_size = SuperpixelTools::computeRegionSizeFromSuperpixels(image, 137 superpixels); 138 139 boost::timer timer; 140 CCS_OpenCV::computeSuperpixels(image, region_size, 141 iterations, compactness, lab, labels); 142 float elapsed = timer.elapsed(); 143 total += elapsed; 144 145 int unconnected_components = SuperpixelTools::relabelConnectedSuperpixels(labels); 146 int merged_components = SuperpixelTools::enforceMinimumSuperpixelSizeUpTo(image, labels, unconnected_components); 147 merged_components += SuperpixelTools::enforceMinimumSuperpixelSizeUpTo(image, labels, unconnected_components); 148 149 if (wordy) { 150 std::cout << SuperpixelTools::countSuperpixels(labels) << " superpixels for " << it->first 151 << " (" << unconnected_components << " not connected; " 152 << merged_components << " merged; " 153 << elapsed <<")." << std::endl; 154 } 155 156 if (!output_dir.empty()) { 157 boost::filesystem::path csv_file(output_dir 158 / boost::filesystem::path(prefix + it->second.stem().string() + ".csv")); 159 IOUtil::writeMatCSV<int>(csv_file, labels); 160 } 161 162 if (!vis_dir.empty()) { 163 boost::filesystem::path contours_file(vis_dir 164 / boost::filesystem::path(prefix + it->second.stem().string() + ".png")); 165 cv::Mat image_contours; 166 Visualization::drawContours(image, labels, image_contours); 167 cv::imwrite(contours_file.string(), image_contours); 168 } 169 } 170 171 if (wordy) { 172 std::cout << "Average time: " << total / images.size() << "." << std::endl; 173 } 174 175 if (!output_dir.empty()) { 176 std::ofstream runtime_file(output_dir.string() + "/" + prefix + "runtime.txt", 177 std::ofstream::out | std::ofstream::app); 178 179 runtime_file << total / images.size() << "\n"; 180 runtime_file.close(); 181 } 182 183 return 0; 184} 185

c_cpp_properties.json

1{ 2 "configurations": [ 3 { 4 "name": "Win32", 5 "includePath": [ 6 "${workspaceFolder}/**", 7 "C:\\opencv-4.7.0\\include", 8 "C:\\boost_1_81_0" 9 ], 10 "defines": [ 11 "_DEBUG", 12 "UNICODE", 13 "_UNICODE" 14 ], 15 "compilerPath": "C:\\MinGW\\bin\\gcc.exe", 16 "cStandard": "gnu17", 17 "cppStandard": "gnu++14", 18 "intelliSenseMode": "windows-gcc-x86" 19 } 20 ], 21 "version": 4 22} 23 24

試したこと

c_cpp_properties.jsonに「"C:\opencv\build\include","C:\boost_1_81_0"」
を追加し、#include <boost/〇〇.hpp>の同様のエラーはなくなったのですが、#include <opencv2/opencv.hpp>に対するエラーが消えません。

opencv2の中にopencv.hppがあることは確認できています。

補足情報(FW/ツールのバージョンなど)

VS Code, opencv-4.7.0, boost_1_81_0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

int32_t

2023/02/01 21:56

c_cpp_properties.json によると C:\opencv-4.7.0\include\opencv2\opencv.hpp が存在しないといけません。「試したこと」によると C:\opencv\build\include\opencv2\opencv.hpp が存在しないといけません。実際にはどのディレクトリに opencv.hpp があるのでしょうか?
nsan_goodjob

2023/02/01 22:03

質問ありがとうございます。 https://opencv.org/releases/ こちらの最新版をダウンロードしたのですが、Cドライブ直下に保存したため、C:\opencv-4.7.0\include\opencv2\opencv.hppにあります。 そのため、c_cpp_properties.jsonにC:\opencv-4.7.0\includeを追加しました。 C:\opencv\build\include\opencv2\opencv.hpp こちらは何のディレクトリでしょうか?
yominet

2023/02/02 01:00

ご自身で、 >c_cpp_properties.jsonに「"C:\opencv\build\include","C:\boost_1_81_0"」 buildを入っているパスを指定していますね このパスと「#include <opencv2/opencv.hpp>」を組み合わせて C:\opencv\build\include\opencv2\opencv.hpp が生成されています。
int32_t

2023/02/02 01:06

> C:\opencv-4.7.0\include\opencv2\opencv.hppにあります。 であれば、質問文の c_cpp_properties.json で問題ないように見えます。 ビルドはどのように行ってますか? VSCode でビルドする方法は何通りかあります。 VSCode ではなく単純にコマンドプロンプトからビルドを試してもいいかもしれませんね。CMakeList.txt があるなら cmake でビルドするのが簡単かもしれません。
guest

回答1

0

そういうのは赤の他人に聞くんじゃなく、まずはその作者に聞くべきものでしょう

投稿2023/02/02 00:47

y_waiwai

総合スコア87774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問