C/C++
入力画像は、アルファチャンネルあり、なしBGR、グレースケールの3種類に対応した。 アルファチャンネルは8bitの4チャンネルの4つ目で、0-255で与える。0の場合は完全に透過する。 今回は、BGRの輝度値が真っ白付近(245-255)を透過する条件とした。 変換前(…
過去に、ROOTとPythonで正規分布のフィッティングをした。 phst.hateblo.jp だが、ROOTはWindowsでx64と共存しないので、x64と共存するライブラリだけを使ったフィッティングを試みた。まずは、 ガウス分布のフィッティング用のサンプルデータ Sample data …
cpuid x86およびx64で使用可能な命令(訳注: 拡張命令含む)を生成します。この命令は、サポートされている機能とCPUタイプに関する情報をプロセッサに問い合わせます。 docs.microsoft.com 実行例 Surface Book 2 GenuineIntel Intel(R) Core(TM) i7-8650U CP…
CPUは複数あるので並列化できるが、出力は並列にする意味がない。また、CPUを使った処理は順不同で良いが、出力は順に行いたい。こういう目的のためには、ThreadPoolと、std::condition_variableを使う。 以下の例では、友人が作ってくれた ThreadPool を使…
OpenCVで画像をPNGファイル、すなわち可逆な形式で圧縮し、ファイルで出力することなくデータを取得したいとき、 cv::imencode というエンコード関数を使う。原理的には以下のように記述する。(そのままでは動かないよ) vector<int> params = vector<int>(2); params[0</int></int>…
PocoとOpenCVによる画像の共有メモリ経由での書き込み・読み出しの実装例 画像を共有メモリから読み出す OpenCVには、画像の先頭のポインタ sm.begin() を与えると自動的に画像として読んでくれるコンストラクタがあるので、それを利用した。 書き込む方と同…
引数に --gtest_catch_exceptions=0 を追加する stackoverflow.com
C++ OpenCVの導入、サンプル画像の作り方は Visual Studio 2017 + OpenCV 3.2.0 + x64の初期設定 とOpenCVに関する質問の受け付け(コメント欄へ) - 物理の駅 by onsanai を参照されたし。 cv::encode cv::decode を使うと、ファイル出力なしに出力用のバイト…
Visual Studio 2019 プレビュー版の16.6が3月16日に公開されていたので、先日報告した件が修正されているか試した。 phst.hateblo.jp docs.microsoft.com #include <filesystem> #include <iostream> #include <fstream> #include <stdio.h> int main(int argc, char** argv) { std::error_code ec; s</stdio.h></fstream></iostream></filesystem>…
三項演算子の戻り値に基底クラスと派生クラスを入れた場合、派生クラスの型は基底クラスに変換できないため、 どちらからも共通して変換できる基底クラスが戻ってくる 。 コード協力: H氏 #include <iostream> struct A { int func() const { return 0; } }; struct B </iostream>…
Hドライブで、ファイルの保存用にResilient File System (ReFS)を使ってる。 std::filesystem::remove がエラーコード 50で、この要求はサポートされていません。が帰ってきた。 ソースコード #include <filesystem> #include <iostream> int main() { std::error_code ec; std::fi</iostream></filesystem>…
点列を表すのにOpenCVの cv::Point2f を使ったが、OpenCVライブラリは使ってないので適宜置き換えて欲しい。 最後から1つめと、最後の点との距離はlengthではない。 std::vector<cv::Point2f> cell_length(const std::vector<cv::Point2f>& points, double length) { assert(points.siz</cv::point2f></cv::point2f>…
CCDカメラは読み出し方式による縞々模様(1行ごとに輝度の濃淡が発生する)現象が起こる。 通常、ハードウェア側で調整されるものだが、ソフトウェア側で調整する必要に迫られたので、そのコードを公開する。 なお、Visual Studio + C# + OpenCVSharp と C++を…
Can I call a constructor from another constructor (do constructor chaining) in C++? stackoverflow.com class Foo { public: Foo(char x, int y) {} Foo(int y) : Foo('a', y) {} };
1>x:\boost_1_65_0\boost\operators.hpp(839): error C4996: 'std::iterator<std::output_iterator_tag,void,void,void,void>': warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. (The <iterator> header is NOT deprecated.) The C++ Standard</iterator></std::output_iterator_tag,void,void,void,void>…
#include <future> #include <mutex> #include <iostream> std::mutex mtx3; class MyClass3 { int long_calc1(int j) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); mtx3.lock(); std::cout << "1 a" << std::endl; mtx3.unlock(); std::this_thread::sleep_for(</iostream></mutex></future>…
#include <future> #include <thread> #include <vector> #include <iostream> #include <mutex> // 標準出力のmutex std::mutex mtx_; int long_calc(int i) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); mtx_.lock(); std::cout << "a" << i << std::endl; mtx_.unlock(); std:</mutex></iostream></vector></thread></future>…
#include <thread> std::this_thread::sleep_for(std::chrono::milliseconds(1));</thread>
The limitation of the size for the std::ofstream write is not 2GB in Visual Studio 2017. The limitation would be 64bit limits. std::vector<uchar> v(0x100000000); // 4GB (=2^32) std::ofstream ofs("o", std::ios::binary); ofs.write((char*)&v[0], v.s</uchar>…
BoostのPython用ライブラリを使いたかったのでコンパイルする 参考文献。 Boostライブラリのビルド方法 - boostjp Boost 最新版をソースコードからビルドし、インストール(MSVC ビルドツールを使用)(Windows 上) Visual Studio 2019の x64 Native Tools …
git clone https://github.com/jbeder/yaml-cpp cmake for Windowsで、 Where is the source code に ***/yaml-cpp Where to build the binaries に ***/yaml-cpp/build Configure から Visual Studio 2019 x64 を選ぶ Xドライブにインストールしたい。Debug…
ピークの周波数によって、途中のBoxFilterとGaussianBlurのカーネルサイズは変えると良い。 背景の強度を求めて、有意度を求めるのがこのプログラムのミソである。 var size = new OpenCvSharp.Size(nbin, nbin); Mat signal = Mat.Zeros(size, MatType.CV_3…
uint64_t range = 1000; int x = 0; int y = 0; uint64_t loop = 0; uint64_t shift = 0; for (uint64_t i = 1; i < range * range; i++) { std::cout<<x<<" "<<y<<" "<<i<<std::endl; if (i == (loop * 2 + 1) * (loop * 2 + 1)) { loop++; shift = 0; x++; } else { shift++; if (shift >= loop * 6) { x++; } else if (s…</x<<">
VS2017 VS2019の環境では、 /std:c++latest または /std:c++17 をコンパイルオプションに追加する必要がある。 具体的な作業は、プロジェクトのオプション→C/C++→言語→C++言語標準 で /std:c++latest または /std:c++17 を追加する。/std:c++latest は実験的…
tbb.dll (例)のフルパスを得る方法と、実行中のexeそのもののフルパスを得る方法 char path[2048]; GetModuleFileNameA(GetModuleHandleA("tbb.dll"), path, 2048); cout << path; GetModuleFileNameA(NULL, path, 2048); cout << path; pathに日本語名が入…
OpenCV 2系でGPUで膨張処理をさせる方法で詰まったので書いておく。最後に検証に使った全コードがあるのでどうぞ。 CPUで膨張処理をさせるとき、さくっと書けば次のようになる。 cv::Mat src, dst; int width = 256; int height = 256; src = cv::Mat::eye(c…
(ja) パターンマッチング可能な飛跡ファイル https://1drv.ms/f/s!Ap9xAxIuzM0xlLxu6slGIjkY3gSjNg Q1. どういう手段でもいいので、 beam_4372-2_u.txt の飛跡と beam_4372-2_d.txt の飛跡の位置ずれを計算しよう。 Q2. 計算方法について、互いに紹介しよう…
Read track files Track struct has 6 members. four double members and two int members. The double members include position x, position y, angle x, angle y. The int members include pulse height and pulse height volume. Q1. Make track class. …
参照: ATLAS Japan C++ Course -- Lesson 2 サンプルコード1 #include <iostream> #include <cstdint> using namespace std; int main(int argc, char** argv) { cout << "char min. = " << int(INT8_MIN) << " max. = " << int(INT8_MAX) << endl << "short int min. = " << IN</cstdint></iostream>…
picojson.h は https://github.com/kazuho/picojson/blob/master/picojson.h からダウンロードすべし。 #include "picojson.h" #include <string> #include <iostream> #include <fstream> #include <sstream> //テキストファイルの読み取り inline std::string read_txt(std::string const& path</sstream></fstream></iostream></string>…