<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
  <title>whoopsidaisies&#39;s diary</title>
  
  <link href="https://whoopsidaisies.hatenablog.com/"/>
  <updated>2019-12-18T19:00:34+09:00</updated>
  <author>
    <name>whoopsidaisies</name>
  </author>
  <generator uri="https://blog.hatena.ne.jp/" version="e8ea2d753d4e685db7f41513a688b5">Hatena::Blog</generator>
  <id>hatenablog://blog/6435988827676239766</id>

  
    
    
    <entry>
        <title>Detectron2のModel Zooで物体検出、インスタンスセグメンテーション、姿勢推定</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2019/12/18/190034"/>
        <id>hatenablog://entry/26006613486122887</id>
        <published>2019-12-18T19:00:34+09:00</published>
        <updated>2019-12-18T19:00:34+09:00</updated>        <summary type="html">概要 Detectron2のModel Zooにある訓練済みを使って、物体検出やインスタンスセグメンテーション、姿勢推定等を行う。 多くのモデルに対して一括で処理できるコードを作った。便利。 Detectron2 FacebookのAI研究グループ（FAIR）が開発している物体検出アルゴリズムを実装のためのソフトウェア。 環境 ubuntu 18.04 GeForce GTX TITAN X インストール 詳細は省略。ほぼ公式の通りやった。Windowsでやろうとしたら公式対応してないから大変そうな雰囲気。 メモ代わりに大雑把な手順を載せるが公式を読んでやったほうがいい。 OS、cuda等：d…</summary>
        <content type="html">&lt;h1&gt;概要&lt;/h1&gt;

&lt;p&gt;Detectron2のModel Zooにある訓練済みを使って、物体検出や&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A4%A5%F3%A5%B9%A5%BF%A5%F3%A5%B9&quot;&gt;インスタンス&lt;/a&gt;セグメンテーション、姿勢推定等を行う。
多くのモデルに対して一括で処理できるコードを作った。便利。&lt;/p&gt;

&lt;h1&gt;&lt;a href=&quot;https://github.com/facebookresearch/detectron2&quot;&gt;Detectron2&lt;/a&gt;&lt;/h1&gt;

&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Facebook&quot;&gt;Facebook&lt;/a&gt;のAI研究グループ（FAIR）が開発している物体検出&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;を実装のためのソフトウェア。&lt;/p&gt;

&lt;h1&gt;環境&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/ubuntu&quot;&gt;ubuntu&lt;/a&gt; 18.04&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/GeForce%20GTX&quot;&gt;GeForce GTX&lt;/a&gt; TITAN X&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;インストール&lt;/h1&gt;

&lt;p&gt;詳細は省略。ほぼ公式の通りやった。&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Windows&quot;&gt;Windows&lt;/a&gt;でやろうとしたら公式対応してないから大変そうな雰囲気。&lt;/p&gt;

&lt;p&gt;メモ代わりに大雑把な手順を載せるが公式を読んでやったほうがいい。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS、cuda等：dockerコンテナ利用

&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/nvidia&quot;&gt;nvidia&lt;/a&gt;/cuda:10.1-cudnn7-devel&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Python&quot;&gt;Python&lt;/a&gt;環境

&lt;ul&gt;
&lt;li&gt;Anaconda 2019.10でpython3.7環境構築&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;pytorch

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;conda install pytorch torchvision cudatoolkit=10.1 -c pytorch&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;detectron2&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  git clone https://github.com/facebookresearch/detectron2.git
  cd detectron2
  python setup.py build develop
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;&lt;a href=&quot;https://github.com/facebookresearch/detectron2/blob/master/MODEL_ZOO.md&quot;&gt;Detectron2 Model Zoo&lt;/a&gt;&lt;/h1&gt;

&lt;p&gt;学習済みのモデルが置いてある。
以下のようなものがあるが、詳細は&lt;a href=&quot;https://github.com/facebookresearch/detectron2/blob/master/MODEL_ZOO.md&quot;&gt;ウェブサイト&lt;/a&gt;参照。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;タスク

&lt;ul&gt;
&lt;li&gt;COCO Object Detection&lt;/li&gt;
&lt;li&gt;COCO Instance Segmentation&lt;/li&gt;
&lt;li&gt;COCO Person Keypoint Detection&lt;/li&gt;
&lt;li&gt;COCO Panoptic Segmentation&lt;/li&gt;
&lt;li&gt;LVIS Instance Segmentation&lt;/li&gt;
&lt;li&gt;Cityscapes&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Pascal&quot;&gt;Pascal&lt;/a&gt; VOC&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Faster R-CNN、RetinaNet、Mask R-CNN、&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Cascade&quot;&gt;Cascade&lt;/a&gt; R-CNN等&lt;/li&gt;
&lt;li&gt;backbone: &lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/FPN&quot;&gt;FPN&lt;/a&gt;、ResNetベースのもの&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;確認用コード&lt;/h1&gt;

&lt;p&gt;Model Zooにある学習済みモデルをロードするモジュールと、予測して可視化するためのモジュールがあったのでそれを使った。&lt;/p&gt;

&lt;p&gt;以下のコードを実行するとModel Zooにあるモデルの42個について予測を行える。&lt;/p&gt;

&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; detectron2.data.detection_utils &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; read_image
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; detectron2.model_zoo.model_zoo &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; ModelZooUrls
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; detectron2.config &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; get_cfg
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; demo.predictor &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; VisualizationDemo

img_path = &lt;span class=&quot;synConstant&quot;&gt;&#39;input.jpg&#39;&lt;/span&gt;
img = read_image(img_path, &lt;span class=&quot;synIdentifier&quot;&gt;format&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;BGR&amp;quot;&lt;/span&gt;)

&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; i, config_path &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;enumerate&lt;/span&gt;(ModelZooUrls.CONFIG_PATH_TO_URL_SUFFIX.keys()):
    &lt;span class=&quot;synComment&quot;&gt;# rpnとfast_rcnnは可視化対応していないので飛ばす&lt;/span&gt;
    &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;&#39;rpn&#39;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; config_path &lt;span class=&quot;synStatement&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;&#39;fast_rcnn&#39;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; config_path:
        &lt;span class=&quot;synStatement&quot;&gt;continue&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;# config設定&lt;/span&gt;
    cfg = get_cfg()
    cfg.merge_from_file(f&lt;span class=&quot;synConstant&quot;&gt;&#39;configs/{config_path}&#39;&lt;/span&gt;)
    cfg.MODEL.WEIGHTS = ModelZooUrls.get(config_path)
    score_thresh = &lt;span class=&quot;synConstant&quot;&gt;0.5&lt;/span&gt;
    cfg.MODEL.RETINANET.SCORE_THRESH_TEST = score_thresh
    cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = score_thresh
    cfg.MODEL.PANOPTIC_FPN.COMBINE.INSTANCES_CONFIDENCE_THRESH = score_thresh
    cfg.freeze()
    &lt;span class=&quot;synComment&quot;&gt;# 検出＆可視化&lt;/span&gt;
    demo = VisualizationDemo(cfg)
    predictions, visualized_output = demo.run_on_image(img)
    &lt;span class=&quot;synComment&quot;&gt;# ファイル出力&lt;/span&gt;
    dataset_name, algorithm = config_path.split(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;/&amp;quot;&lt;/span&gt;)
    algorithm = algorithm.split(&lt;span class=&quot;synConstant&quot;&gt;&#39;.&#39;&lt;/span&gt;)[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;]
    visualized_output.save(f&lt;span class=&quot;synConstant&quot;&gt;&#39;out/{i:02d}-{dataset_name}-{algorithm}.jpg&#39;&lt;/span&gt;)
&lt;/pre&gt;


&lt;h1&gt;結果&lt;/h1&gt;

&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181902.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181902j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181902j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181904.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181904j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181904j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181907.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181907j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181907j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181911.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181911j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181911j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181914.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181914j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181914j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181916.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181916j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181916j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181921.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181921j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181921j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181926.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181926j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181926j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181930.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181930j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181930j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181932.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181932j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181932j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181935.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181935j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181935j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181937.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181937j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181937j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181940.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181940j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181940j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181943.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181943j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181943j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181945.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181945j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181945j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181947.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181947j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181947j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181950.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181950j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181950j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181953.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181953j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181953j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181956.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181956j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181956j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181959.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181959j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181959j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182001.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182001j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182001j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182004.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182004j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182004j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182007.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182007j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182007j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182010.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182010j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182010j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182013.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182013j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182013j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182016.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182016j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182016j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182020.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182020j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182020j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182023.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182023j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182023j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182026.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182026j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182026j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182029.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182029j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182029j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182031.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182031j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182031j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182035.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182035j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182035j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182039.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182039j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182039j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182041.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182041j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182041j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182044.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182044j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182044j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182047.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182047j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182047j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182051.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182051j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182051j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182055.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182055j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182055j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182059.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182059j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182059j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182101.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182101j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182101j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;div class=&quot;images-row mceNonEditable&quot;&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182104.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182104j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182104j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218182107.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218182107j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218182107j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181911.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181911j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181911j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20191218/20191218181907.jpg&quot; alt=&quot;f:id:whoopsidaisies:20191218181907j:plain&quot; title=&quot;f:id:whoopsidaisies:20191218181907j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;&lt;div class=&quot;images-row mceNonEditable&quot;&gt;&lt;/p&gt;
</content>        
        <category term="Deep Learning" label="Deep Learning" />
        
        <category term="Programming" label="Programming" />
        
        <category term="python" label="python" />
        
        <category term="機械学習" label="機械学習" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/d42166be9f2fd89e986485c6599b5b45acd31a1f/backend=imagemagick;version=1;width=1300/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20191218%2F20191218182817.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>denseposeでU.S.A.</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2018/12/03/193759"/>
        <id>hatenablog://entry/10257846132679628996</id>
        <published>2018-12-03T19:37:59+09:00</published>
        <updated>2018-12-03T19:37:59+09:00</updated>        <summary type="html">youtu.be 完全に出遅れたけど、DensePose使ってみたのでメモ。 Facebook等が発表した、2次元画像から人体の3Dサーフェスモデルを推定しちゃうすごい手法。 詳細とか使い方は下記のページあたりを参照。 shiropen.com github.com 環境 ubuntu 16.04 nvidia-docker導入済み（nvidia-dockerインストール、コンテナ等メモ - whoopsidaisies&#39;s diary） 導入 偉い人がdockerhubでイメージ公開してくれていたので活用。 動画ファイルをffmpegとかで画像にばらしておいた。 # ubuntu 16.04…</summary>
        <content type="html">&lt;p&gt;&lt;iframe width=&quot;480&quot; height=&quot;270&quot; src=&quot;https://www.youtube.com/embed/RONOvSMnlV0?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://youtu.be/RONOvSMnlV0&quot;&gt;youtu.be&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;完全に出遅れたけど、&lt;a href=&quot;https://qiita.com/syoyo/items/e9193d18b0970950b9c6:embed&quot;&gt;DensePose&lt;/a&gt;使ってみたのでメモ。
&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Facebook&quot;&gt;Facebook&lt;/a&gt;等が発表した、2次元画像から人体の3D&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%B5%A1%BC%A5%D5%A5%A7%A5%B9&quot;&gt;サーフェス&lt;/a&gt;モデルを推定しちゃうすごい手法。&lt;/p&gt;

&lt;p&gt;詳細とか使い方は下記のページあたりを参照。&lt;/p&gt;

&lt;p&gt;&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fshiropen.com%2Fseamless%2Ffacebook-ai-densepose&quot; title=&quot;Facebookら、2Dの群衆動画から人間の姿勢を推定し、身体のテクチャも貼ってくれるCNNを用いたシステム「DensePose」オープンソース発表&quot; class=&quot;embed-card embed-webcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 155px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://shiropen.com/seamless/facebook-ai-densepose&quot;&gt;shiropen.com&lt;/a&gt;&lt;/cite&gt;
&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fgithub.com%2Ffacebookresearch%2FDensePose&quot; title=&quot;facebookresearch/DensePose&quot; class=&quot;embed-card embed-webcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 155px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://github.com/facebookresearch/DensePose&quot;&gt;github.com&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;h1&gt;環境&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/ubuntu&quot;&gt;ubuntu&lt;/a&gt; 16.04&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/nvidia&quot;&gt;nvidia&lt;/a&gt;-docker導入済み（&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2017/01/22/190618&quot;&gt;nvidia-docker&amp;#x30A4;&amp;#x30F3;&amp;#x30B9;&amp;#x30C8;&amp;#x30FC;&amp;#x30EB;&amp;#x3001;&amp;#x30B3;&amp;#x30F3;&amp;#x30C6;&amp;#x30CA;&amp;#x7B49;&amp;#x30E1;&amp;#x30E2; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;）&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;導入&lt;/h1&gt;

&lt;p&gt;偉い人が&lt;a href=&quot;https://hub.docker.com/r/garyfeng/densepose/&quot;&gt;dockerhubでイメージ公開&lt;/a&gt;してくれていたので活用。
動画ファイルを&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/ffmpeg&quot;&gt;ffmpeg&lt;/a&gt;とかで画像にばらしておいた。&lt;/p&gt;

&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;# ubuntu 16.04の端末で
nvidia-docker run -it -d --name densepose garyfeng/densepose
docker exec -it densepose bash
# コンテナ内
#   実行時の引数でフォルダを指定するとフォルダ内の画像を一気に処理してくれる
tools/infer_simple.py \
   --cfg configs/DensePose_ResNet101_FPN_s1x-e2e.yaml \
   --output-dir /root/data/infer_out/  \
   --image-ext png \
   --wts https://s3.amazonaws.com/densepose/DensePose_ResNet101_FPN_s1x-e2e.pkl \
   /root/data/frame&lt;/pre&gt;


&lt;p&gt;以上、簡単にできてすごい。&lt;/p&gt;
</content>        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/7455678c0ca2effa15a632e6bc4578bd2f120ff3/backend=imagemagick;version=1;width=1300/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20181203%2F20181203193521.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>OpenCV 3.4.1で背景差分</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2018/03/01/130000"/>
        <id>hatenablog://entry/17391345971620851816</id>
        <published>2018-03-01T13:00:00+09:00</published>
        <updated>2018-03-01T13:31:22+09:00</updated>        <summary type="html">OpenCV 3.4.1により背景差分のアルゴリズム7種類を比較。Google Summer of Code 2017で生まれたアルゴリズムの結果がきれいだった。C++、Pythonのサンプルコードあり。</summary>
        <content type="html">&lt;h1&gt;背景差分&lt;/h1&gt;

&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20180301/20180301131807.png&quot; alt=&quot;f:id:whoopsidaisies:20180301131807p:plain&quot; title=&quot;f:id:whoopsidaisies:20180301131807p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;画像の前景と背景を分離する手法。2013年に&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/18/092142&quot;&gt;OpenCV 2.4.7での背景差分の記事&lt;/a&gt;を書いたが、2018年になったいま&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/OpenCV&quot;&gt;OpenCV&lt;/a&gt; 3.4.1で背景差分を行おうとしたら使える&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;が増えていたのでまとめておく。&lt;/p&gt;

&lt;h1&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;&lt;/h1&gt;

&lt;h2&gt;MOG, MOG2, GMG&lt;/h2&gt;

&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/OpenCV&quot;&gt;OpenCV&lt;/a&gt; 2.4.7でも使えた。以下のページに日本語でわかりやすい説明がある。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://lang.sist.chukyo-u.ac.jp/classes/OpenCV/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html&quot;&gt;&amp;#x80CC;&amp;#x666F;&amp;#x5DEE;&amp;#x5206; &amp;mdash; OpenCV-Python Tutorials&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;KNN&lt;/h2&gt;

&lt;p&gt;K近傍方に基づく背景差分。前景の画&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%C1%C7%BF%F4&quot;&gt;素数&lt;/a&gt;が少ない場合は効率が良いらしい。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.sciencedirect.com/science/article/pii/S0167865505003521&quot;&gt;Efficient adaptive density estimation per image pixel for the task of background subtraction - ScienceDirect&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;CNT&lt;/h2&gt;

&lt;p&gt;低スペックな計算機でもほかの&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;より高速に処理ができる。CNTという名前は「CouNT」の省略らしい。Raspberry Pi3での&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%D9%A5%F3%A5%C1%A5%DE%A1%BC%A5%AF&quot;&gt;ベンチマーク&lt;/a&gt;ではMOG2が41秒に対し、CNTは18秒。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://sagi-z.github.io/BackgroundSubtractorCNT/&quot;&gt;https://sagi-z.github.io/BackgroundSubtractorCNT/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;LSBP&lt;/h2&gt;

&lt;p&gt;Local &lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt; Binary Pattern。注目画素とその周辺画素の大小関係を符号化するLBP（Local Binary Pattern）は、高速に計算可能な画像特徴量として知られている。局所的なノイズや隣接画素が類似しているような場合にも&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%ED%A5%D0%A5%B9%A5%C8&quot;&gt;ロバスト&lt;/a&gt;にするようにSVD（&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%C6%C3%B0%DB%C3%CD%CA%AC%B2%F2&quot;&gt;特異値分解&lt;/a&gt;）を使った特徴量で背景差分を行っているそう。&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A4%C1%A4%E3%A4%F3&quot;&gt;ちゃん&lt;/a&gt;と勉強してないのでよくわらからない。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.cv-foundation.org/openaccess/content_cvpr_2016_workshops/w24/papers/Guo_Background_Subtraction_Using_CVPR_2016_paper.pdf&quot;&gt;https://www.cv-foundation.org/openaccess/content_cvpr_2016_workshops/w24/papers/Guo_Background_Subtraction_Using_CVPR_2016_paper.pdf&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;GSOC&lt;/h2&gt;

&lt;p&gt;LSBP特徴を使ってる。ノイズ除去とか穴埋めといった後処理をしているらしい。GSOC(&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Google&quot;&gt;Google&lt;/a&gt; &lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Summer%20of%20Code&quot;&gt;Summer of Code&lt;/a&gt;)2017中で開発されたとかで元論文等はないらしいので&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%BD%A1%BC%A5%B9%A5%B3%A1%BC%A5%C9&quot;&gt;ソースコード&lt;/a&gt;を読もう。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/opencv/opencv_contrib/blob/6520dbaa224a661ca8105b1ab0b71451fd715f4c/modules/bgsegm/src/bgfg_gsoc.cpp&quot;&gt;opencv_contrib/bgfg_gsoc.cpp at 6520dbaa224a661ca8105b1ab0b71451fd715f4c &amp;middot; opencv/opencv_contrib &amp;middot; GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;コード&lt;/h1&gt;

&lt;p&gt;実行には&lt;a href=&quot;https://github.com/opencv/opencv_contrib&quot;&gt;opencv_contrib&lt;/a&gt;が必要。&lt;/p&gt;

&lt;h2&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/C%2B%2B&quot;&gt;C++&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;opencv_contrib&lt;/code&gt;をダウンロードし、&lt;code&gt;opencv&lt;/code&gt;の&lt;code&gt;cmake&lt;/code&gt;時に例えば以下のように&lt;code&gt;OPENCV_EXTRA_MODULES_PATH&lt;/code&gt;オプションを指定してビルドする。&lt;/p&gt;

&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;$ cmake -DOPENCV_EXTRA_MODULES_PATH=&amp;lt;opencv_contrib&amp;gt;/modules -DBUILD_opencv_legacy=OFF &amp;lt;opencv_source_directory&amp;gt;&lt;/pre&gt;


&lt;h4&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%BD%A1%BC%A5%B9%A5%B3%A1%BC%A5%C9&quot;&gt;ソースコード&lt;/a&gt;&lt;/h4&gt;

&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/opencv.hpp&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/core/utility.hpp&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/bgsegm.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; main()
{
    &lt;span class=&quot;synComment&quot;&gt;// 動画ファイルの読み込み&lt;/span&gt;
    cv::VideoCapture cap = cv::VideoCapture(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;video.mp4&amp;quot;&lt;/span&gt;);
    &lt;span class=&quot;synComment&quot;&gt;// 背景差分器の生成&lt;/span&gt;
    cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::bgsegm::createBackgroundSubtractorGSOC();
    &lt;span class=&quot;synComment&quot;&gt;//cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::bgsegm::createBackgroundSubtractorCNT();&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;//cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::bgsegm::createBackgroundSubtractorGMG();&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;//cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::bgsegm::createBackgroundSubtractorLSBP();&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;//cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::bgsegm::createBackgroundSubtractorMOG();&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;//cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::createBackgroundSubtractorMOG2();&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;//cv::Ptr&amp;lt;cv::BackgroundSubtractor&amp;gt; bgfs = cv::createBackgroundSubtractorKNN();&lt;/span&gt;

    &lt;span class=&quot;synStatement&quot;&gt;while&lt;/span&gt; (cv::waitKey(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;) == -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;)
    {
        cv::Mat frame, foreGroundMask, segm;

        cap &amp;gt;&amp;gt; frame;
        &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; (frame.empty())
            &lt;span class=&quot;synStatement&quot;&gt;break&lt;/span&gt;;

        bgfs-&amp;gt;apply(frame, foreGroundMask);
        frame.convertTo(segm, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0.5&lt;/span&gt;);
        cv::add(frame, cv::Scalar(&lt;span class=&quot;synConstant&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;), segm, foreGroundMask);
    
        cv::imshow(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;output&amp;quot;&lt;/span&gt;, segm);
    }
    &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;;
}
&lt;/pre&gt;


&lt;h2&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Python&quot;&gt;Python&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;pip&lt;/code&gt;で管理している場合、以下のように&lt;code&gt;opencv-python&lt;/code&gt;をアンインストール後に&lt;code&gt;opencv-contrib-python&lt;/code&gt;をインストールすれば&lt;code&gt;opencv_contrib&lt;/code&gt;が使える。&lt;/p&gt;

&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;pip uninstall opencv-python
pip install opencv-contrib-python&lt;/pre&gt;


&lt;h4&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%BD%A1%BC%A5%B9%A5%B3%A1%BC%A5%C9&quot;&gt;ソースコード&lt;/a&gt;&lt;/h4&gt;

&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; cv2

cap = cv2.VideoCapture(&lt;span class=&quot;synConstant&quot;&gt;&#39;video.mp4&#39;&lt;/span&gt;)
bgs = cv2.bgsegm.createBackgroundSubtractorLSBP()

&lt;span class=&quot;synStatement&quot;&gt;while&lt;/span&gt;(cap.isOpened()):
    ret, frame = cap.read()
    mask = bgs.&lt;span class=&quot;synIdentifier&quot;&gt;apply&lt;/span&gt;(frame)
    bg = bgs.getBackgroundImage()
    cv2.imshow(&lt;span class=&quot;synConstant&quot;&gt;&#39;mask&#39;&lt;/span&gt;, mask)
    cv2.imshow(&lt;span class=&quot;synConstant&quot;&gt;&#39;bg&#39;&lt;/span&gt;, bg)
    &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; cv2.waitKey(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;) != -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;:
        &lt;span class=&quot;synStatement&quot;&gt;break&lt;/span&gt;

cap.release()
cv2.destroyAllWindows()
&lt;/pre&gt;


&lt;h1&gt;適用結果&lt;/h1&gt;

&lt;p&gt;比較のために各&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;を並べてみた。パラメータ調整もしてないから比較もくそもない気はするけど。GSOCが綺麗。LSBPはあんまり&lt;/p&gt;

&lt;p&gt;&lt;iframe width=&quot;459&quot; height=&quot;344&quot; src=&quot;https://www.youtube.com/embed/EILZ4YsI6rU?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=EILZ4YsI6rU&quot;&gt;www.youtube.com&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;あと、背景差分やるだけだったらたぶん以下のページで紹介されている&lt;a href=&quot;https://github.com/andrewssobral/bgslibrary&quot;&gt;BGSLibrary&lt;/a&gt;を使ったほうが良さそうではある。&lt;/p&gt;

&lt;p&gt;&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.negativemind.com%2F2017%2F07%2F12%2Fbgslibrary%2F&quot; title=&quot;OpenCVベースの背景差分ライブラリ『BGSLibrary』&quot; class=&quot;embed-card embed-webcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 155px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://blog.negativemind.com/2017/07/12/bgslibrary/&quot;&gt;blog.negativemind.com&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;
</content>        
        <category term="C++" label="C++" />
        
        <category term="Deep Learning" label="Deep Learning" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="python" label="python" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/c60292f193a01c77ebf5ebdd5ce320404f08dc80/backend=imagemagick;version=1;width=1300/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20180301%2F20180301131807.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>tensorflowでMASK R-CNNによるSemantic Segmentation</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2018/02/27/184448"/>
        <id>hatenablog://entry/17391345971620252496</id>
        <published>2018-02-27T18:44:48+09:00</published>
        <updated>2018-02-27T18:44:48+09:00</updated>        <summary type="html">TensorFlow Object Detection APIを用いてMask R-CNNによる画像のセマンティックセグメンテーションを行った。</summary>
        <content type="html">&lt;h1&gt;セマンティックセグメンテーション&lt;/h1&gt;

&lt;p&gt;下の写真みたいに、入力画像を物体ごとに領域分割する技術。&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20180227/20180227180905.png&quot; alt=&quot;f:id:whoopsidaisies:20180227180905p:plain&quot; title=&quot;f:id:whoopsidaisies:20180227180905p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;
&lt;a href=&quot;https://wiki.tum.de/display/lfdv/Image+Semantic+Segmentation&quot;&gt;https://wiki.tum.de/display/lfdv/Image+Semantic+Segmentation&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;h1&gt;Mask R-CNN&lt;/h1&gt;

&lt;p&gt;数あるセマンティックセグメンテーションを実現する手法の中で、2018年2月現在有力とされているものの一つ（たぶん）。&lt;/p&gt;

&lt;p&gt;&lt;iframe width=&quot;480&quot; height=&quot;270&quot; src=&quot;https://www.youtube.com/embed/OOT3UIXZztE?feature=oembed&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=OOT3UIXZztE&quot;&gt;www.youtube.com&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%A2%A5%EB%A5%B4%A5%EA%A5%BA%A5%E0&quot;&gt;アルゴリズム&lt;/a&gt;の詳細についての説明は他に譲る。以下のページとかを参考にする。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://arxiv.org/pdf/1703.06870.pdf&quot;&gt;https://arxiv.org/pdf/1703.06870.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://kaiminghe.com/iccv17tutorial/maskrcnn_iccv2017_tutorial_kaiminghe.pdf&quot;&gt;http://kaiminghe.com/iccv17tutorial/maskrcnn_iccv2017_tutorial_kaiminghe.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://deeplearning.csail.mit.edu/instance_ross.pdf&quot;&gt;http://deeplearning.csail.mit.edu/instance_ross.pdf&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;TensorFlowのインストール&lt;/h1&gt;

&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/Google%C0%E8%C0%B8&quot;&gt;Google先生&lt;/a&gt;が公開している&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%B5%A1%B3%A3%B3%D8%BD%AC&quot;&gt;機械学習&lt;/a&gt;用&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%AA%A1%BC%A5%D7%A5%F3%A5%BD%A1%BC%A5%B9&quot;&gt;オープンソース&lt;/a&gt;ライブラリ。インストール方法は巷にあふれているので適当にググってインストールする。&lt;/p&gt;

&lt;h1&gt;Tensorflow Object Detection &lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/API&quot;&gt;API&lt;/a&gt;のインストール&lt;/h1&gt;

&lt;p&gt;以下の&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/GitHub&quot;&gt;GitHub&lt;/a&gt;のレポジトリで様々なTensorfFlowのモデルが公開されている。公式サポートではないが物体検出とセマンティックセグメンテーションのモデルも数多く公開されているので、今回はそれを使う。&lt;/p&gt;

&lt;p&gt;&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fgithub.com%2Ftensorflow%2Fmodels&quot; title=&quot;tensorflow/models&quot; class=&quot;embed-card embed-webcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 155px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;&lt;cite class=&quot;hatena-citation&quot;&gt;&lt;a href=&quot;https://github.com/tensorflow/models&quot;&gt;github.com&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;インストールは公式の手順通りだが以下に適当にメモ。
&lt;a href=&quot;https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md&quot;&gt;models/installation.md at master &amp;middot; tensorflow/models &amp;middot; GitHub&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;依存パッケージのインストール&lt;/li&gt;
&lt;/ul&gt;


&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;apt install protobuf-compiler
pip install pillow lxml jupyter matplotlib&lt;/pre&gt;


&lt;ul&gt;
&lt;li&gt;Protobufファイルを&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%B3%A5%F3%A5%D1%A5%A4%A5%EB&quot;&gt;コンパイル&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;cd [PATH to models]/research
protoc object_detection/protos/*.proto --python_out=.&lt;/pre&gt;


&lt;ul&gt;
&lt;li&gt;PYTHONPATHの追加&lt;/li&gt;
&lt;/ul&gt;


&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;cd [PATH to models]/research
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim&lt;/pre&gt;


&lt;h1&gt;モデルファイルのダウンロード&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md&quot;&gt;Tensorflow detection model zoo&lt;/a&gt;から物体検出やセマンティックセグメンテーションのトレーニング済みモデルをダウンロード出来る。とりあえず一番mAPの高い&lt;a href=&quot;http://download.tensorflow.org/models/object_detection/mask_rcnn_inception_resnet_v2_atrous_coco_2018_01_28.tar.gz&quot;&gt;mask_rcnn_inception_resnet_v2_atrous_coco&lt;/a&gt;というモデルを使う。&lt;/p&gt;

&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;wget http://download.tensorflow.org/models/object_detection/mask_rcnn_inception_resnet_v2_atrous_coco_2018_01_28.tar.gz
tar -zxvf mask_rcnn_inception_resnet_v2_atrous_coco_2018_01_28.tar.gz&lt;/pre&gt;


&lt;h1&gt;セマンティックセグメンテーションの&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/python&quot;&gt;python&lt;/a&gt;コード&lt;/h1&gt;

&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; tensorflow &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; tf
&lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; numpy &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; np
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; PIL &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; Image
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; object_detection.utils &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; ops &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; utils_ops

&lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; sys
sys.path.append(&lt;span class=&quot;synConstant&quot;&gt;&#39;[modelsのパス]/research/object_detection&#39;&lt;/span&gt;)
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; utils &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; label_map_util
&lt;span class=&quot;synPreProc&quot;&gt;from&lt;/span&gt; utils &lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; visualization_utils &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; vis_util

&lt;span class=&quot;synComment&quot;&gt;# 学習済モデルの読み込み&lt;/span&gt;
PATH_TO_CKPT = &lt;span class=&quot;synConstant&quot;&gt;&#39;mask_rcnn_inception_resnet_v2_atrous_coco_2018_01_28/frozen_inference_graph.pb&#39;&lt;/span&gt;

detection_graph = tf.Graph()
&lt;span class=&quot;synStatement&quot;&gt;with&lt;/span&gt; detection_graph.as_default():
  od_graph_def = tf.GraphDef()
  &lt;span class=&quot;synStatement&quot;&gt;with&lt;/span&gt; tf.gfile.GFile(PATH_TO_CKPT, &lt;span class=&quot;synConstant&quot;&gt;&#39;rb&#39;&lt;/span&gt;) &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; fid:
    serialized_graph = fid.read()
    od_graph_def.ParseFromString(serialized_graph)
    tf.import_graph_def(od_graph_def, name=&lt;span class=&quot;synConstant&quot;&gt;&#39;&#39;&lt;/span&gt;)

&lt;span class=&quot;synComment&quot;&gt;# ラベルの読み込み&lt;/span&gt;
PATH_TO_LABELS = &lt;span class=&quot;synConstant&quot;&gt;&#39;[modelsへのパス]/research/object_detection/data/mscoco_label_map.pbtxt&#39;&lt;/span&gt;
NUM_CLASSES = &lt;span class=&quot;synConstant&quot;&gt;90&lt;/span&gt;

label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=&lt;span class=&quot;synIdentifier&quot;&gt;True&lt;/span&gt;)
category_index = label_map_util.create_category_index(categories)

&lt;span class=&quot;synComment&quot;&gt;# 画像の読み込みとnumpy配列への変換&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;load_image_into_numpy_array&lt;/span&gt;(image):
  (im_width, im_height) = image.size
  &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; np.array(image.getdata()).reshape(
      (im_height, im_width, &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;)).astype(np.uint8)

filename = &lt;span class=&quot;synConstant&quot;&gt;&#39;[画像ファイルのパス]&#39;&lt;/span&gt;
image = Image.&lt;span class=&quot;synIdentifier&quot;&gt;open&lt;/span&gt;(filename)
image_np = load_image_into_numpy_array(image)

&lt;span class=&quot;synComment&quot;&gt;# セマンティックセグメンテーションの処理&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;with&lt;/span&gt; detection_graph.as_default():
    &lt;span class=&quot;synStatement&quot;&gt;with&lt;/span&gt; tf.Session() &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; sess:
        &lt;span class=&quot;synComment&quot;&gt;# 入出力用テンソルのハンドルを取得&lt;/span&gt;
        image_tensor = tf.get_default_graph().get_tensor_by_name(&lt;span class=&quot;synConstant&quot;&gt;&#39;image_tensor:0&#39;&lt;/span&gt;)
        tensor_dict = {}
        tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;num_detections&#39;&lt;/span&gt;] = tf.get_default_graph().get_tensor_by_name(&lt;span class=&quot;synConstant&quot;&gt;&#39;num_detections:0&#39;&lt;/span&gt;)
        tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_boxes&#39;&lt;/span&gt;] = tf.get_default_graph().get_tensor_by_name(&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_boxes:0&#39;&lt;/span&gt;)
        tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_scores&#39;&lt;/span&gt;] = tf.get_default_graph().get_tensor_by_name(&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_scores:0&#39;&lt;/span&gt;)
        tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_classes&#39;&lt;/span&gt;] = tf.get_default_graph().get_tensor_by_name(&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_classes:0&#39;&lt;/span&gt;)
        tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks&#39;&lt;/span&gt;] = tf.get_default_graph().get_tensor_by_name(&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks:0&#39;&lt;/span&gt;)
        
        &lt;span class=&quot;synComment&quot;&gt;# バッチ内の最初の画像の結果を取り出す&lt;/span&gt;
        detection_boxes = tf.squeeze(tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_boxes&#39;&lt;/span&gt;], [&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;])
        detection_masks = tf.squeeze(tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks&#39;&lt;/span&gt;], [&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;])
        
        &lt;span class=&quot;synComment&quot;&gt;# 各検出ボックスのマスクを画像全体上のマスクへ変換&lt;/span&gt;
        real_num_detection = tf.cast(tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;num_detections&#39;&lt;/span&gt;][&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;], tf.int32)
        detection_boxes = tf.&lt;span class=&quot;synIdentifier&quot;&gt;slice&lt;/span&gt;(detection_boxes, [&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;], [real_num_detection, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;])
        detection_masks = tf.&lt;span class=&quot;synIdentifier&quot;&gt;slice&lt;/span&gt;(detection_masks, [&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;], [real_num_detection, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;])
        detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks(
            detection_masks, detection_boxes, image_np.shape[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;], image_np.shape[&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;])
        detection_masks_reframed = tf.cast(
            tf.greater(detection_masks_reframed, &lt;span class=&quot;synConstant&quot;&gt;0.5&lt;/span&gt;), tf.uint8)
        
        &lt;span class=&quot;synComment&quot;&gt;# バッチ分の次元を追加&lt;/span&gt;
        tensor_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks&#39;&lt;/span&gt;] = tf.expand_dims(
            detection_masks_reframed, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;)
        
        &lt;span class=&quot;synComment&quot;&gt;# 実行&lt;/span&gt;
        output_dict = sess.run(tensor_dict,
                               feed_dict={image_tensor: np.expand_dims(image_np, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;)})
        
        &lt;span class=&quot;synComment&quot;&gt;# バッチ分の次元の削除と型変換&lt;/span&gt;
        output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;num_detections&#39;&lt;/span&gt;] = &lt;span class=&quot;synIdentifier&quot;&gt;int&lt;/span&gt;(output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;num_detections&#39;&lt;/span&gt;][&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;])
        output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_classes&#39;&lt;/span&gt;] = output_dict[
            &lt;span class=&quot;synConstant&quot;&gt;&#39;detection_classes&#39;&lt;/span&gt;][&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;].astype(np.uint8)
        output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_boxes&#39;&lt;/span&gt;] = output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_boxes&#39;&lt;/span&gt;][&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;]
        output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_scores&#39;&lt;/span&gt;] = output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_scores&#39;&lt;/span&gt;][&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;]
        output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks&#39;&lt;/span&gt;] = output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks&#39;&lt;/span&gt;][&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;]

&lt;span class=&quot;synComment&quot;&gt;# 画像にマスクとバウンディングボックスを書き込んで出力&lt;/span&gt;
vis_util.visualize_boxes_and_labels_on_image_array(
    image_np,
    output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_boxes&#39;&lt;/span&gt;],
    output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_classes&#39;&lt;/span&gt;],
    output_dict[&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_scores&#39;&lt;/span&gt;],
    category_index,
    instance_masks=output_dict.get(&lt;span class=&quot;synConstant&quot;&gt;&#39;detection_masks&#39;&lt;/span&gt;),
    use_normalized_coordinates=&lt;span class=&quot;synIdentifier&quot;&gt;True&lt;/span&gt;,
    line_thickness=&lt;span class=&quot;synConstant&quot;&gt;8&lt;/span&gt;)
Image.fromarray(image_np).save(&lt;span class=&quot;synConstant&quot;&gt;&#39;out.png&#39;&lt;/span&gt;)
&lt;/pre&gt;


&lt;h1&gt;結果&lt;/h1&gt;

&lt;p&gt;拾ってきたフリー写真に適用した結果が以下。手だけ写ってても人間って判断してくれるのね。&lt;/p&gt;

&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;https://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20180227/20180227183425.png&quot; alt=&quot;f:id:whoopsidaisies:20180227183425p:plain&quot; title=&quot;f:id:whoopsidaisies:20180227183425p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;
</content>        
        <category term="python" label="python" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <category term="機械学習" label="機械学習" />
        
        <category term="Deep Learning" label="Deep Learning" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/29048580bbbf7a684272dbdceb314da9a9798b63/backend=imagemagick;version=1;width=1300/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20180227%2F20180227183425.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>nvidia-dockerインストール、コンテナ等メモ</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2017/01/22/190618"/>
        <id>hatenablog://entry/10328749687208981069</id>
        <published>2017-01-22T19:06:18+09:00</published>
        <updated>2017-01-22T19:06:18+09:00</updated>        <summary type="html">基本的に公式サイトの説明とかの通りにやるだけなんだけど自分用にメモ。 ホストOS：ubuntu 16.04LTS dockerのインストール 参考： Get Docker for Ubuntu - Docker # https通信で公開鍵ダウンロードするため apt-get update apt-get install curl ca-certificates # dockerレポジトリの公開鍵の登録 curl -fsSL https://yum.dockerproject.org/gpg | apt-key add - # add-apt-repositoryコマンドのインストール apt-…</summary>
        <content type="html">&lt;p&gt;基本的に公式サイトの説明とかの通りにやるだけなんだけど自分用にメモ。&lt;/p&gt;

&lt;p&gt;ホストOS：&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/ubuntu&quot;&gt;ubuntu&lt;/a&gt; 16.04LTS&lt;/p&gt;

&lt;h1&gt;dockerのインストール&lt;/h1&gt;

&lt;p&gt;参考：
&lt;a href=&quot;https://docs.docker.com/engine/installation/linux/ubuntu/&quot;&gt;&lt;img src=&quot;https://cdn-ak.favicon.st-hatena.com/?url=https%3A%2F%2Fdocs.docker.com%2Fengine%2Finstallation%2Flinux%2Fubuntu%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://docs.docker.com/engine/installation/linux/ubuntu/&quot;&gt;Get Docker for Ubuntu - Docker&lt;/a&gt;&lt;/p&gt;

&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;# https通信で公開鍵ダウンロードするため
apt-get update
apt-get install curl ca-certificates

# dockerレポジトリの公開鍵の登録
curl -fsSL https://yum.dockerproject.org/gpg | apt-key add -

# add-apt-repositoryコマンドのインストール
apt-get install software-properties-common

# dockerレポジトリ追加
add-apt-repository &amp;#34;deb https://apt.dockerproject.org/repo/ ubuntu-$(lsb_release -cs) main&amp;#34;

# aptでhttps通信するため
apt-get install apt-transport-https

# dockerのインストール
apt-get update
apt-get install docker-engine&lt;/pre&gt;


&lt;h1&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/NVIDIA&quot;&gt;NVIDIA&lt;/a&gt;ドライバのインストール&lt;/h1&gt;

&lt;p&gt;これが一番ハマって大変な場合が多い気がするが、ここでは省略。どうにかうまいことインストールする。&lt;/p&gt;

&lt;h1&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/NVIDIA&quot;&gt;NVIDIA&lt;/a&gt; Dockerのインストール&lt;/h1&gt;

&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;# debパッケージのダウンロード（2017/1/22現在で最新のもの）
curl -LO https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.0/nvidia-docker_1.0.0-1_amd64.deb
# インストール
dpkg -i nvidia-docker_1.0.0-1_amd64.deb
rm nvidia-docker_1.0.0-1_amd64.deb
# 動作確認（GPU情報が表示されると良い）
nvidia-docker run --rm nvidia/cuda nvidia-smi&lt;/pre&gt;


&lt;p&gt;バージョンについては下記ページでチェックして適宜ダウンロードするものを確認する。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/NVIDIA/nvidia-docker/releases&quot;&gt;&lt;img src=&quot;https://cdn-ak.favicon.st-hatena.com/?url=https%3A%2F%2Fgithub.com%2FNVIDIA%2Fnvidia-docker%2Freleases&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://github.com/NVIDIA/nvidia-docker/releases&quot;&gt;Releases &amp;middot; NVIDIA/nvidia-docker &amp;middot; GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/NVIDIA&quot;&gt;NVIDIA&lt;/a&gt; Dockerコンテナメモ&lt;/h1&gt;

&lt;p&gt;便利なものがあれば随時追記予定。&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://hub.docker.com/u/nvidia/&quot;&gt;https://hub.docker.com/u/nvidia/&lt;/a&gt;&lt;br/&gt;
&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/nvidia&quot;&gt;nvidia&lt;/a&gt;公式コンテナ。CUDAやCuDNNのバージョン、OSの種類を選べる。&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://hub.docker.com/u/kaixhin/&quot;&gt;https://hub.docker.com/u/kaixhin/&lt;/a&gt;&lt;br/&gt;
イギリスの研究者作成のコンテナ。色々あって便利。&lt;/li&gt;
&lt;/ul&gt;

</content>        
        <link rel="enclosure" href="https://ogimage.blog.st-hatena.com/6435988827676239766/10328749687208981069/1485079578" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#で3次元グラフを表示する ILNumerics </title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/12/02/183247"/>
        <id>hatenablog://entry/8454420450075953018</id>
        <published>2014-12-02T18:32:47+09:00</published>
        <updated>2014-12-02T18:32:47+09:00</updated>        <summary type="html">ILNumericsは.NETで使用可能な数値計算等のライブラリである．グラフ表示機能も備わっているので，それを使ってC#のWindowsフォーム上に3次元グラフを表示する． ILNumericsのインストール 現在最新バージョン（4.x系）のILNumericsは14日間のトライアル版以外は有償だが，Community Editionという無償版が提供されていた3.x系のバージョンがNuGetでインストール可能なのでそれを使う．まず，Visual StudioでWindowsフォームアプリケーションを作成する．そして，プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オン…</summary>
        <content type="html">&lt;p&gt;&lt;a href=&quot;http://ilnumerics.net/&quot;&gt;ILNumerics&lt;/a&gt;は.NETで使用可能な数値計算等のライブラリである．グラフ表示機能も備わっているので，それを使ってC#のWindowsフォーム上に3次元グラフを表示する．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ILNumericsのインストール&lt;/h3&gt;
    &lt;p&gt;現在最新バージョン（4.x系）のILNumericsは&lt;a href=&quot;http://ilnumerics.net/shop.html&quot;&gt;14&amp;#x65E5;&amp;#x9593;&amp;#x306E;&amp;#x30C8;&amp;#x30E9;&amp;#x30A4;&amp;#x30A2;&amp;#x30EB;&amp;#x7248;&amp;#x4EE5;&amp;#x5916;&amp;#x306F;&amp;#x6709;&amp;#x511F;&lt;/a&gt;だが，&lt;a href=&quot;http://ilnumerics.net/closed-source-version-available.html&quot;&gt;Community Edition&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x7121;&amp;#x511F;&amp;#x7248;&amp;#x304C;&amp;#x63D0;&amp;#x4F9B;&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x305F;3.x&amp;#x7CFB;&amp;#x306E;&amp;#x30D0;&amp;#x30FC;&amp;#x30B8;&amp;#x30E7;&amp;#x30F3;&lt;/a&gt;が&lt;a href=&quot;https://www.nuget.org/packages/ILNumerics/&quot;&gt;NuGet&amp;#x3067;&amp;#x30A4;&amp;#x30F3;&amp;#x30B9;&amp;#x30C8;&amp;#x30FC;&amp;#x30EB;&amp;#x53EF;&amp;#x80FD;&lt;/a&gt;なのでそれを使う．&lt;/p&gt;&lt;p&gt;まず，Visual StudioでWindowsフォームアプリケーションを作成する．&lt;/p&gt;&lt;p&gt;そして，プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「ILNumerics」を検索・インストールする．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;グラフ表示用コントロールの配置&lt;/h3&gt;
    &lt;p&gt;フォームデザイナを開きツールボックスの適当なところで右クリックして「アイテムの選択(I)...」を選択する．&lt;/p&gt;&lt;p&gt;「.NET Framework コンポーネント」タブの「参照(B)...」ボタンを押して，「(ソリューションのパス)\packages\ILNumerics.3.3.3.0\lib\ILNumerics.dll」を選択したらOK．&lt;/p&gt;&lt;p&gt;するとツールボックスIL○○というコントロールが追加される．その中の，ILPanelコントロールをフォーム上に配置する．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141202/20141202163400.png&quot; alt=&quot;f:id:whoopsidaisies:20141202163400p:plain&quot; title=&quot;f:id:whoopsidaisies:20141202163400p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;使ってみる&lt;/h3&gt;
    
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;曲面&lt;/h4&gt;
    &lt;p&gt;例として，以下の2変数関数を表示させてみる．&lt;br /&gt;
&lt;img src=&quot;http://chart.apis.google.com/chart?cht=tx&amp;chl=z%3D%5Cfrac%7B%5Csin%28%5Csqrt%7Bx%5E2%2By%5E2%7D%29%7D%7B%5Csqrt%7Bx%5E2%2By%5E2%7D%7D&quot; alt=&quot;z=\frac{\sin(\sqrt{x^2+y^2})}{\sqrt{x^2+y^2}}&quot;/&gt;&lt;/p&gt;&lt;p&gt;まず，コードの適当な場所に以下のusingを書いておく．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; ILNumerics.Drawing;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; ILNumerics.Drawing.Plotting;
&lt;/pre&gt;&lt;p&gt;そして，フォームロードイベントとかの適当なイベントに以下のコードを書く．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// グラフを格納するオブジェクトの生成&lt;/span&gt;
var scene = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILScene
{
    &lt;span class=&quot;synComment&quot;&gt;// 3次元モードでプロット領域を生成&lt;/span&gt;
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILPlotCube(twoDMode: &lt;span class=&quot;synConstant&quot;&gt;false&lt;/span&gt;)
    {
        &lt;span class=&quot;synComment&quot;&gt;// 曲面の生成&lt;/span&gt;
        &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILSurface(
            (x,y) =&amp;gt; (&lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;)(
                Math.Sin(Math.Sqrt(x*x + y*y))/Math.Sqrt(x*x + y*y)))
    }
};
&lt;span class=&quot;synComment&quot;&gt;// 描画用コントロールに生成したグラフをセット&lt;/span&gt;
ilPanel1.Scene = scene;
&lt;/pre&gt;&lt;p&gt;実行すると以下のように3次元グラフが表示される．マウスドラッグとかホイールとかで視点や拡大率を変えられる．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141202/20141202172655.png&quot; alt=&quot;f:id:whoopsidaisies:20141202172655p:plain&quot; title=&quot;f:id:whoopsidaisies:20141202172655p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;等高線&lt;/h4&gt;
    &lt;p&gt;サンプル用の地形データも用意されていて，以下のように使うことが出来る．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;var scene = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILScene
{
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILPlotCube(twoDMode: &lt;span class=&quot;synConstant&quot;&gt;false&lt;/span&gt;){
        &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILSurface(ILNumerics.ILMath.tosingle(ILNumerics.ILSpecialData.terrain))
    }
};
ilPanel1.Scene = scene;
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141202/20141202180125.png&quot; alt=&quot;f:id:whoopsidaisies:20141202180125p:plain&quot; title=&quot;f:id:whoopsidaisies:20141202180125p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;ここまでは曲面表示のためILSurfaceクラスを使ってきたが，ILContourPlotクラスを使えば以下のように等高線表示も出来る．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;var scene = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILScene
{
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILPlotCube{
        &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILContourPlot(ILNumerics.ILMath.tosingle(ILNumerics.ILSpecialData.terrain))
    }
};
ilPanel1.Scene = scene;
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141202/20141202180132.png&quot; alt=&quot;f:id:whoopsidaisies:20141202180132p:plain&quot; title=&quot;f:id:whoopsidaisies:20141202180132p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;散布図&lt;/h4&gt;
    &lt;p&gt;ILPointsクラスで散布図を表示させることも出来る．以下はランダムに点を打って対数軸にして表示した例．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;ILNumerics.ILArray&amp;lt;&lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;&amp;gt; p = ILNumerics.ILMath.tosingle(ILNumerics.ILMath.rand(&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;10000&lt;/span&gt;));
var scene = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILScene{
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILPlotCube(twoDMode:&lt;span class=&quot;synConstant&quot;&gt;false&lt;/span&gt;){
        &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ILPoints
        {
            Positions = p,
            Color = &lt;span class=&quot;synConstant&quot;&gt;null&lt;/span&gt;,
            Colors =  p,
            Size = &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;,
        }
    }
};
var scaleModes = scene.First&amp;lt;ILPlotCube&amp;gt;().ScaleModes;
scaleModes.XAxisScale = AxisScale.Logarithmic;
scaleModes.YAxisScale = AxisScale.Logarithmic;
scaleModes.ZAxisScale = AxisScale.Logarithmic;

ilPanel1.Scene = scene;
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141202/20141202182150.png&quot; alt=&quot;f:id:whoopsidaisies:20141202182150p:plain&quot; title=&quot;f:id:whoopsidaisies:20141202182150p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;</content>        
        <category term=".NET" label=".NET" />
        
        <category term="C#" label="C#" />
        
        <category term="NuGet" label="NuGet" />
        
        <category term="可視化" label="可視化" />
        
        <category term="Programming" label="Programming" />
        
        <category term="Windows フォーム アプリケーション" label="Windows フォーム アプリケーション" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/8fc5c6e4e151c7d18cadbadd8e24e728444b5662/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141202%2F20141202183047.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>Python+OpenCVで特徴量記述・アルゴリズムまとめ</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/12/01/235013"/>
        <id>hatenablog://entry/8454420450075890810</id>
        <published>2014-12-01T23:50:13+09:00</published>
        <updated>2014-12-01T23:50:13+09:00</updated>        <summary type="html">Python+OpenCVで画像の特徴点の特徴量を記述する．OpenCV2.4.9およびOpenCV3.0 alphaについて使用できるアルゴリズムをまとめる．Python+OpenCVで特徴点抽出・使えるアルゴリズムまとめ OpenCV2.4.9と3.0 alpha - whoopsidaisies&#39;s diary の続き． 環境 WindowsでOpenCV公式サイトのダウンロードページから2.4.9および3.0 alphaのビルド済みバイナリをダウンロードしてきて解凍したものを使う． 特徴量記述器の使い方 特徴点抽出のときのFeatureDetectorと同じように，特徴量記述についても…</summary>
        <content type="html">&lt;p&gt;Python+OpenCVで画像の特徴点の特徴量を記述する．OpenCV2.4.9およびOpenCV3.0 alphaについて使用できるアルゴリズムをまとめる．&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/12/01/031213&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2014%2F12%2F01%2F031213&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/12/01/031213&quot;&gt;Python+OpenCV&amp;#x3067;&amp;#x7279;&amp;#x5FB4;&amp;#x70B9;&amp;#x62BD;&amp;#x51FA;&amp;#x30FB;&amp;#x4F7F;&amp;#x3048;&amp;#x308B;&amp;#x30A2;&amp;#x30EB;&amp;#x30B4;&amp;#x30EA;&amp;#x30BA;&amp;#x30E0;&amp;#x307E;&amp;#x3068;&amp;#x3081; OpenCV2.4.9&amp;#x3068;3.0 alpha - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
の続き．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;環境&lt;/h3&gt;
    &lt;p&gt;WindowsでOpenCV公式サイトの&lt;a href=&quot;http://opencv.org/downloads.html&quot;&gt;&amp;#x30C0;&amp;#x30A6;&amp;#x30F3;&amp;#x30ED;&amp;#x30FC;&amp;#x30C9;&amp;#x30DA;&amp;#x30FC;&amp;#x30B8;&lt;/a&gt;から&lt;a href=&quot;https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.9/opencv-2.4.9.exe/download&quot;&gt;2.4.9&lt;/a&gt;および&lt;a href=&quot;http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0-alpha/&quot;&gt;3.0 alpha&lt;/a&gt;のビルド済みバイナリをダウンロードしてきて解凍したものを使う．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;特徴量記述器の使い方&lt;/h3&gt;
    &lt;p&gt;特徴点抽出のときのFeatureDetectorと同じように，特徴量記述についてもDescriptorExtractorという共通インターフェースが用意されている．&lt;/p&gt;&lt;p&gt;使い方は以下の通り．&lt;/p&gt;
&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;# 引数でどの特徴量記述子を使うか指定 &lt;/span&gt;
extractor = cv2.DescriptorExtractor_create(extractor_name)
&lt;span class=&quot;synComment&quot;&gt;# 引数として画像と特徴点を渡す&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;# 戻り値は特徴点と特徴量&lt;/span&gt;
keypoints, descriptors = extractor.compute(img, keypoints)
&lt;/pre&gt;&lt;p&gt;DescriptorExtractor_createメソッドで指定出来る特徴量記述子を以下にまとめた．&lt;/p&gt;

&lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;OpenCVバージョン&lt;/td&gt;
    &lt;th&gt; 実数ベクトル&lt;/th&gt;
    &lt;th&gt; バイナリコード&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td&gt;2.4.9&lt;/td&gt;
    &lt;td&gt;SIFT, SURF&lt;/td&gt;
    &lt;td&gt;BRIEF, BRISK, &lt;del&gt;ORB&lt;/del&gt;, FREAK&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td&gt;3.0 alpha&lt;/td&gt;
    &lt;td&gt;KAZE&lt;/td&gt;
    &lt;td&gt;AKAZE, BRISK, ORB&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;（2.4.9でORBがなぜかランタイムエラーが出るので追々調査予定）&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;特徴量の中身&lt;/h3&gt;
    &lt;p&gt;descriptorsの中身は2次元のarrayになっており，特徴点ごとに特徴量のベクトルが格納されている．&lt;/p&gt;&lt;p&gt;KAZEで記述した特徴量を表示してみるとこんな感じ（0番目の点）．&lt;/p&gt;
&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&amp;gt;&amp;gt;descriptors[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;]
array([ -&lt;span class=&quot;synConstant&quot;&gt;7.38840317e-04&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;6.34267868e-04&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.61819176e-03&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;3.50267510e-03&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;1.59906253e-04&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;4.56994586e-03&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;4.39605350e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;9.44076758e-03&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;1.75689301e-03&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;8.05667194e-04&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;3.55383591e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;4.12554527e-03&lt;/span&gt;,
        -&lt;span class=&quot;synConstant&quot;&gt;1.54193444e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.58668880e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.78847502e-03&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;3.14337271e-03&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;1.62520558e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.65848620e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;3.65739577e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.07063138e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.64649391e-02&lt;/span&gt;,
        -&lt;span class=&quot;synConstant&quot;&gt;6.13974873e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;9.64385048e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.91850477e-01&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;5.54781593e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;6.74537197e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;6.74520805e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;8.45865980e-02&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;2.12559430e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.18403265e-03&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;5.09992335e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;4.04977519e-03&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;1.28035052e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;6.93068025e-04&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;3.93203236e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;4.54802722e-01&lt;/span&gt;,
        -&lt;span class=&quot;synConstant&quot;&gt;2.96720478e-04&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;6.83288351e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;8.15773308e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;6.17026806e-01&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;1.08468741e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;5.95125668e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;1.92962006e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.17324436e-01&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;1.21422755e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;2.50244630e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.34693161e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;6.25377288e-03&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;2.55310140e-03&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;4.21544649e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.98030730e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;1.50349155e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;4.27789390e-02&lt;/span&gt;,  -&lt;span class=&quot;synConstant&quot;&gt;9.73087847e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;1.63991615e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.90487400e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;3.39032081e-03&lt;/span&gt;,
        -&lt;span class=&quot;synConstant&quot;&gt;2.32313443e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.98113456e-01&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;6.58137947e-02&lt;/span&gt;,
        -&lt;span class=&quot;synConstant&quot;&gt;1.16498368e-02&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;2.66303378e-03&lt;/span&gt;,   &lt;span class=&quot;synConstant&quot;&gt;1.25482017e-02&lt;/span&gt;,
         &lt;span class=&quot;synConstant&quot;&gt;4.14769724e-03&lt;/span&gt;], dtype=float32)
&lt;/pre&gt;&lt;p&gt;グラフ表示だとこんな感じ．&lt;/p&gt;
&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; plt
plt.plot(descriptors[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;])
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141201/20141201234637.png&quot; alt=&quot;f:id:whoopsidaisies:20141201234637p:plain&quot; title=&quot;f:id:whoopsidaisies:20141201234637p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;KAZEは64次元の実数ベクトルで特徴量記述をするので以上のようになるが，記述子によってデータ量が違うため配列の長さや型が変わってくる．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C++" label="C++" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="OpenCV 3.0" label="OpenCV 3.0" />
        
        <category term="Programming" label="Programming" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <category term="python" label="python" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/db69269e7c38622288177e6241a8bdf28b01f3be/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141201%2F20141201224635.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
    <entry>
        <title>Python+OpenCVで特徴点抽出・使えるアルゴリズムまとめ OpenCV2.4.9と3.0 alpha</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/12/01/031213"/>
        <id>hatenablog://entry/8454420450075787134</id>
        <published>2014-12-01T03:12:13+09:00</published>
        <updated>2014-12-01T03:12:13+09:00</updated>        <summary type="html">軽量プログラミング言語が苦手なので敬遠していたが，世間ではPythonからOpenCVを呼ぶのが流行っているようなので，練習がてらOpenCVで使える特徴点抽出アルゴリズムをまとめてみる．OpenCV2.4.9とOpenCV3.0 alphaについてまとめる．3.0 betaはなぜか動かなかったのでいつか暇があれば調査． 環境 WindowsでOpenCV公式サイトのダウンロードページから2.4.9および3.0 alphaのビルド済みバイナリをダウンロードしてきて解凍したものを使う．PythonからのOpenCVの呼び出し方はこことかを参照． 特徴点抽出の使い方 OpenCVで実装されている特…</summary>
        <content type="html">&lt;p&gt;軽量プログラミング言語が苦手なので敬遠していたが，世間ではPythonからOpenCVを呼ぶのが流行っているようなので，練習がてらOpenCVで使える特徴点抽出アルゴリズムをまとめてみる．&lt;/p&gt;&lt;p&gt;OpenCV2.4.9とOpenCV3.0 alphaについてまとめる．3.0 betaはなぜか動かなかったのでいつか暇があれば調査．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;環境&lt;/h3&gt;
    &lt;p&gt;WindowsでOpenCV公式サイトの&lt;a href=&quot;http://opencv.org/downloads.html&quot;&gt;&amp;#x30C0;&amp;#x30A6;&amp;#x30F3;&amp;#x30ED;&amp;#x30FC;&amp;#x30C9;&amp;#x30DA;&amp;#x30FC;&amp;#x30B8;&lt;/a&gt;から&lt;a href=&quot;https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.9/opencv-2.4.9.exe/download&quot;&gt;2.4.9&lt;/a&gt;および&lt;a href=&quot;http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0-alpha/&quot;&gt;3.0 alpha&lt;/a&gt;のビルド済みバイナリをダウンロードしてきて解凍したものを使う．&lt;/p&gt;&lt;p&gt;PythonからのOpenCVの呼び出し方は&lt;a href=&quot;http://docs.opencv.org/trunk/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html&quot;&gt;&amp;#x3053;&amp;#x3053;&amp;#x3068;&amp;#x304B;&lt;/a&gt;を参照．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;特徴点抽出の使い方&lt;/h3&gt;
    &lt;p&gt;OpenCVで実装されている特徴点抽出のアルゴリズムはいくつかあるが，FeatureDetectorという共通インターフェースを使うことでどのアルゴリズムでも同様の記述で使える．使い方は以下．&lt;/p&gt;
&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;# 画像読み込み&lt;/span&gt;
img = cv2.imread(&lt;span class=&quot;synConstant&quot;&gt;&#39;gazou.bmp&#39;&lt;/span&gt;)
&lt;span class=&quot;synComment&quot;&gt;# FeatureDetectorのインスタンスを生成&lt;/span&gt;
detector = cv2.FeatureDetector_create(detector_type)
&lt;span class=&quot;synComment&quot;&gt;# 特徴点を抽出&lt;/span&gt;
keypoints = detctor.detect(img)
&lt;/pre&gt;&lt;p&gt;FeatureDetector_createメソッドの引数にアルゴリズム名を文字列で渡すことで，どのアルゴリズムで特徴点抽出するかを選択することが出来る．例えば，ORBアルゴリズムで特徴点を抽出して表示するのは以下のようになる．&lt;/p&gt;
&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;import&lt;/span&gt; cv2

img = cv2.imread(&lt;span class=&quot;synConstant&quot;&gt;&#39;gazou.bmp&#39;&lt;/span&gt;)
&lt;span class=&quot;synComment&quot;&gt;# アルゴリズム名を引数で渡す&lt;/span&gt;
detector = cv2.FeatureDetector_create(&lt;span class=&quot;synConstant&quot;&gt;&#39;ORB&#39;&lt;/span&gt;)
keypoints = detctor.detect(img)
&lt;span class=&quot;synComment&quot;&gt;# 画像への特徴点の書き込み&lt;/span&gt;
out = cv2.drawKeypoints(img, keypoints, &lt;span class=&quot;synIdentifier&quot;&gt;None&lt;/span&gt;)
&lt;span class=&quot;synComment&quot;&gt;# 表示&lt;/span&gt;
cv2.imshow(name, out)
cv2.waitKey(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;)
&lt;/pre&gt;&lt;p&gt;結果は以下のようになる．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141201/20141201024751.png&quot; alt=&quot;f:id:whoopsidaisies:20141201024751p:plain&quot; title=&quot;f:id:whoopsidaisies:20141201024751p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;ちなみに特徴点の書き込み部分を以下のようにすると，特徴点のサイズと方向を表す円が描画される．&lt;/p&gt;
&lt;pre class=&quot;code lang-python&quot; data-lang=&quot;python&quot; data-unlink&gt;out = cv2.drawKeypoints(img, keypoints, &lt;span class=&quot;synIdentifier&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;None&lt;/span&gt;, cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141201/20141201024104.png&quot; alt=&quot;f:id:whoopsidaisies:20141201024104p:plain&quot; title=&quot;f:id:whoopsidaisies:20141201024104p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;FeatureDetectorインターフェースで使えるアルゴリズム&lt;/h3&gt;
    &lt;p&gt;FeatureDetectorインターフェースで指定できる特徴点抽出アルゴリズムはOpenCVのバージョンで変わるようなので，OpenCV2.4.9で使えるものとOpenCV3.0 alphaで使えるものを以下にまとめる．&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;

&lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;バージョン&lt;/td&gt;
    &lt;th&gt;アルゴリズム名&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;2.4.9&lt;/th&gt;
    &lt;td&gt;BRISK, Dense, FAST, FASTX, GFTT, HARRIS, MSER, ORB, SIFT, STAR, SURF, SURF_OCL, SimpleBlob&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;3.0 alpha&lt;/th&gt;
    &lt;td&gt;AKAZE, BRISK, FAST, GFTT, HARRIS, KAZE, MSER, ORB, SimpleBlob&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;&lt;br /&gt;
C++版については以下の記事にまとめてある．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/08/20/200215&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2014%2F08%2F20%2F200215&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/08/20/200215&quot;&gt;OpenCV3.0.0-alpha&amp;#x306E;&amp;#x7279;&amp;#x5FB4;&amp;#x62BD;&amp;#x51FA;&amp;#x30FB;&amp;#x30DE;&amp;#x30C3;&amp;#x30C1;&amp;#x30F3;&amp;#x30B0;&amp;#x307E;&amp;#x3068;&amp;#x3081; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/07/135810&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2013%2F12%2F07%2F135810&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/07/135810&quot;&gt;OpenCV&amp;#x3067;&amp;#x753B;&amp;#x50CF;&amp;#x306E;&amp;#x7279;&amp;#x5FB4;&amp;#x62BD;&amp;#x51FA;&amp;#x30FB;&amp;#x30DE;&amp;#x30C3;&amp;#x30C1;&amp;#x30F3;&amp;#x30B0;&amp;#x3092;&amp;#x884C;&amp;#x3046; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="python" label="python" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="OpenCV 3.0" label="OpenCV 3.0" />
        
        <category term="C++" label="C++" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/50d5199a50a55d4580f3ca112e8cacd43401e5bf/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141201%2F20141201024104.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#で画像をWavelet変換 Accord.NET</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/11/30/103221"/>
        <id>hatenablog://entry/8454420450075706497</id>
        <published>2014-11-30T10:32:21+09:00</published>
        <updated>2014-11-30T10:32:21+09:00</updated>        <summary type="html">C#で画像のWavelet変換を行う．コンピュータビジョン等の.NET向けのオープンソースのライブラリであるAccord.NET Frameworkを使う． Accord.NETのインストール NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「Accord.Imaging」を検索・インストール． WaveletTransformクラス Accord.NETのWaveletTransformクラスによってWavelet変換を行える．入力画像はグレースケールで，解像度が2のべき乗でないといけない． ソースコード WaveletT…</summary>
        <content type="html">&lt;p&gt;C#で画像のWavelet変換を行う．コンピュータビジョン等の.NET向けのオープンソースのライブラリである&lt;a href=&quot;http://accord-framework.net/&quot;&gt;Accord.NET Framework&lt;/a&gt;を使う．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Accord.NETのインストール&lt;/h3&gt;
    &lt;p&gt;NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「Accord.Imaging」を検索・インストール．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;WaveletTransformクラス&lt;/h3&gt;
    &lt;p&gt;Accord.NETの&lt;a href=&quot;http://accord-framework.net/docs/html/T_Accord_Imaging_Filters_WaveletTransform.htm&quot;&gt;WaveletTransform&lt;/a&gt;クラスによってWavelet変換を行える．入力画像はグレースケールで，解像度が2のべき乗でないといけない．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;p&gt;WaveletTransformクラスの初期化時にWavelet母関数を指定する．その引数でWavelet変換のレベルを指定できる．ここではHaar関数でレベル2とした．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// 入力画像&lt;/span&gt;
var img = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Bitmap(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Penguins.jpg&amp;quot;&lt;/span&gt;);
&lt;span class=&quot;synComment&quot;&gt;// 画像の解像度が2のべき乗になるように調整&lt;/span&gt;
var bitWidth = Convert.ToString(img.Width - &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;).Length;
var bitHeight = Convert.ToString(img.Height - &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;).Length;
var width = (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;)Math.Pow(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;, bitWidth);
var height = (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;)Math.Pow(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;, bitHeight);
&lt;span class=&quot;synComment&quot;&gt;// 隙間の部分はゼロ埋め&lt;/span&gt;
var imgPadded = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Bitmap(width, height, img.PixelFormat);
var graphics = Graphics.FromImage(imgPadded);
graphics.DrawImage(img, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;);
graphics.Dispose();
&lt;span class=&quot;synComment&quot;&gt;// グレースケール化&lt;/span&gt;
var gray = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; AForge.Imaging.Filters.Grayscale(&lt;span class=&quot;synConstant&quot;&gt;0.2125&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0.7154&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0.0721&lt;/span&gt;).Apply(imgPadded);
&lt;span class=&quot;synComment&quot;&gt;// Wavelet変換クラスの作成&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;//  Harrクラスの初期化時にレベルを指定出来る&lt;/span&gt;
var wavelet = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Accord.Imaging.Filters.WaveletTransform(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Accord.Math.Wavelets.Haar(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;));
&lt;span class=&quot;synComment&quot;&gt;// Wavelet変換&lt;/span&gt;
var imgWavelet = wavelet.Apply(gray);
pictureBox1.Image = imgWavelet;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;結果&lt;/h3&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141130/20141130095415.png&quot; alt=&quot;f:id:whoopsidaisies:20141130095415p:plain&quot; title=&quot;f:id:whoopsidaisies:20141130095415p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;逆変換&lt;/h3&gt;
    &lt;p&gt;WaveletTransformクラスの&lt;a href=&quot;http://accord-framework.net/docs/html/P_Accord_Imaging_Filters_WaveletTransform_Backward.htm&quot;&gt;Backword&lt;/a&gt;プロパティをtrueにしてApplyメソッドを実行すると逆変換が出来る．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;wavelet.Backward = &lt;span class=&quot;synConstant&quot;&gt;true&lt;/span&gt;;
var gyaku = wavelet.Apply(imgWavelet);
&lt;/pre&gt;
&lt;/div&gt;</content>        
        <category term=".NET" label=".NET" />
        
        <category term="Accord.NET" label="Accord.NET" />
        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term="ディジタル画像処理" label="ディジタル画像処理" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/b12ac553788e38682972df11efadec70abc44e13/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141130%2F20141130095415.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
    <entry>
        <title>C#で画像を高速フーリエ変換　AForge.NET</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/11/30/091905"/>
        <id>hatenablog://entry/8454420450075684932</id>
        <published>2014-11-30T09:19:05+09:00</published>
        <updated>2014-11-30T09:19:05+09:00</updated>        <summary type="html">C#で画像の高速フーリエ変換（FFT）を行う．コンピュータビジョン等のライブラリであるAForge.NET Frameworkを使う． AForge.NETのインストール Nuget経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「AForge」で検索．「AForge.Imaging」を選択してインストール． ComplexImageクラス AForge.NETのComplexImageクラスを使うと画像のFFTおよび逆FFTが出来る．入力する画像はグレースケールで解像度が2のべき乗になっている必要がある． ソースコード 画像のグレー…</summary>
        <content type="html">&lt;p&gt;C#で画像の高速フーリエ変換（FFT）を行う．コンピュータビジョン等のライブラリである&lt;a href=&quot;https://code.google.com/p/aforge/&quot;&gt;AForge.NET Framework&lt;/a&gt;を使う．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;AForge.NETのインストール&lt;/h3&gt;
    &lt;p&gt;Nuget経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「AForge」で検索．「AForge.Imaging」を選択してインストール．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ComplexImageクラス&lt;/h3&gt;
    &lt;p&gt;AForge.NETの&lt;a href=&quot;http://www.aforgenet.com/framework/docs/html/8ec218c8-628b-e6b9-c398-3d65f14280d5.htm&quot;&gt;ComplexImage&lt;/a&gt;クラスを使うと画像のFFTおよび逆FFTが出来る．入力する画像はグレースケールで解像度が2のべき乗になっている必要がある．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;p&gt;画像のグレースケール化は&lt;a href=&quot;http://www.aforgenet.com/framework/docs/html/d7196dc6-8176-4344-a505-e7ade35c1741.htm&quot;&gt;Grayscale&lt;/a&gt;クラスを使った．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// 入力画像&lt;/span&gt;
var img = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Bitmap(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Lighthouse.jpg&amp;quot;&lt;/span&gt;);
pictureBox1.Image = img;
&lt;span class=&quot;synComment&quot;&gt;// 画像の解像度が2のべき乗になるように調整&lt;/span&gt;
var bitWidth = Convert.ToString(img.Width - &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;).Length;
var bitHeight = Convert.ToString(img.Height - &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;).Length;
var width = (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;)Math.Pow(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;, bitWidth);
var height = (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;)Math.Pow(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;, bitHeight);
&lt;span class=&quot;synComment&quot;&gt;// 隙間の部分はゼロ埋め&lt;/span&gt;
var imgPadded = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Bitmap(width, height, img.PixelFormat);
var graphics = Graphics.FromImage(imgPadded);
graphics.DrawImage(img, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;);
graphics.Dispose();
&lt;span class=&quot;synComment&quot;&gt;// グレースケール化&lt;/span&gt;
var gray = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; AForge.Imaging.Filters.Grayscale(&lt;span class=&quot;synConstant&quot;&gt;0.2125&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0.7154&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0.0721&lt;/span&gt;).Apply(imgPadded);
pictureBox2.Image = gray;
&lt;span class=&quot;synComment&quot;&gt;// FFT&lt;/span&gt;
var complexImage = AForge.Imaging.ComplexImage.FromBitmap(gray);
complexImage.ForwardFourierTransform();
pictureBox3.Image = complexImage.ToBitmap();
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;結果画像&lt;/h3&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141130/20141130083904.png&quot; alt=&quot;f:id:whoopsidaisies:20141130083904p:plain&quot; title=&quot;f:id:whoopsidaisies:20141130083904p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;FFT後の値&lt;/h3&gt;
    &lt;p&gt;ComplexImageクラスの&lt;a href=&quot;http://www.aforgenet.com/framework/docs/html/5717ee01-e66e-d13d-8578-bdcc862e033f.htm&quot;&gt;Data&lt;/a&gt;プロパティは2次元配列でFFT後の値が格納されている．また，&lt;a href=&quot;http://www.aforgenet.com/framework/docs/html/bf07655f-4048-c890-190a-16859beb1925.htm&quot;&gt;BackwardFourierTransform&lt;/a&gt;メソッドで逆FFTを行える．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term=".NET" label=".NET" />
        
        <category term="AForge.NET" label="AForge.NET" />
        
        <category term="C#" label="C#" />
        
        <category term="ディジタル画像処理" label="ディジタル画像処理" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/016d0e45fc24eecf5cef998f33776a35f53ca51b/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141130%2F20141130083904.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>Visual Studioでデバッグ時にOpenCVのMat等の画像を表示できるプラグインが便利</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/11/28/175637"/>
        <id>hatenablog://entry/8454420450075550903</id>
        <published>2014-11-28T17:56:37+09:00</published>
        <updated>2014-11-28T17:56:37+09:00</updated>        <summary type="html">OpenCV公式サイトのNEWSを見てたら「Image Watch plugin for Visual Studio」というのを見つけた．使ってみたら便利そうだったのでメモ．もっと早く知りたかった．わざわざimshowとかのコードを追加してウィンドウを表示させなくてもMatの中の画像を確認できる．また，拡大表示とか画素値の表示も出来るため通常のOpenCVの画像表示用のウィンドウより便利な気がする． Image Watch plugin for Visual Studioのインストール 以下のサイトからダウンロードしてきて指示にしたがってインストールするだけ． Image Watch exte…</summary>
        <content type="html">&lt;p&gt;&lt;a href=&quot;http://opencv.org/image-watch-plugin-for-visual-studio.html&quot;&gt;OpenCV&amp;#x516C;&amp;#x5F0F;&amp;#x30B5;&amp;#x30A4;&amp;#x30C8;&amp;#x306E;NEWS&lt;/a&gt;を見てたら「&lt;a href=&quot;https://visualstudiogallery.msdn.microsoft.com/e682d542-7ef3-402c-b857-bbfba714f78d&quot;&gt;Image Watch plugin for Visual Studio&lt;/a&gt;」というのを見つけた．使ってみたら便利そうだったのでメモ．もっと早く知りたかった．&lt;/p&gt;&lt;p&gt;わざわざimshowとかのコードを追加してウィンドウを表示させなくてもMatの中の画像を確認できる．また，拡大表示とか画素値の表示も出来るため通常のOpenCVの画像表示用のウィンドウより便利な気がする．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Image Watch plugin for Visual Studioのインストール&lt;/h3&gt;
    &lt;p&gt;以下のサイトからダウンロードしてきて指示にしたがってインストールするだけ．&lt;br /&gt;
&lt;a href=&quot;https://visualstudiogallery.msdn.microsoft.com/e682d542-7ef3-402c-b857-bbfba714f78d&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=https%3A%2F%2Fvisualstudiogallery.msdn.microsoft.com%2Fe682d542-7ef3-402c-b857-bbfba714f78d&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://visualstudiogallery.msdn.microsoft.com/e682d542-7ef3-402c-b857-bbfba714f78d&quot;&gt;Image Watch extension&lt;/a&gt;&lt;/p&gt;&lt;p&gt;以下のサイトに詳しい手順等載ってます．&lt;br /&gt;
&lt;a href=&quot;http://www.atinfinity.info/blog/archives/1601&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.atinfinity.info%2Fblog%2Farchives%2F1601&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.atinfinity.info/blog/archives/1601&quot;&gt;Image Watch&amp;#x306E;&amp;#x4F7F;&amp;#x3044;&amp;#x65B9; | dandelion&amp;#39;s log&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;使ってみる&lt;/h3&gt;
    &lt;p&gt;以下のコードで試してみた．画像を表示させるためのコードは特に必要ない．画像が入っている変数があれば自動で表示してくれる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/opencv.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; cv;

&lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; main()
{
	&lt;span class=&quot;synComment&quot;&gt;// 画像読み込み&lt;/span&gt;
	Mat img = imread(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Penguins.jpg&amp;quot;&lt;/span&gt;);
	&lt;span class=&quot;synComment&quot;&gt;// Sobelフィルタ&lt;/span&gt;
	Mat imgSobel;
	Sobel(img, imgSobel, img.depth(), &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;);
	&lt;span class=&quot;synComment&quot;&gt;// ラプラシアンフィルタ&lt;/span&gt;
	Mat imgLaplacian;
	Laplacian(img, imgLaplacian, img.depth());
	&lt;span class=&quot;synComment&quot;&gt;// Cannyアルゴリズム&lt;/span&gt;
	Mat imgCanny;
	Canny(img, imgCanny, &lt;span class=&quot;synConstant&quot;&gt;50&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;200&lt;/span&gt;);
}
&lt;/pre&gt;&lt;p&gt;一番下の行にブレークポイントを置いて，デバッグ実行して止める．&lt;/p&gt;&lt;p&gt;「表示」メニューの中から「Image Watch」を探してクリックしてウィンドウを表示させる．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141128/20141128173607.png&quot; alt=&quot;f:id:whoopsidaisies:20141128173607p:plain&quot; title=&quot;f:id:whoopsidaisies:20141128173607p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;そうすると以下の様なウィンドウが出てきて，Mat型の変数とその中身の画像が表示される．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141128/20141128165602.png&quot; alt=&quot;f:id:whoopsidaisies:20141128165602p:plain&quot; title=&quot;f:id:whoopsidaisies:20141128165602p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;左側に画像一覧があるので，クリックすれば以下のようにその画像が表示される．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141128/20141128165507.png&quot; alt=&quot;f:id:whoopsidaisies:20141128165507p:plain&quot; title=&quot;f:id:whoopsidaisies:20141128165507p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;マウススクロールで拡大可能．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141128/20141128173940.png&quot; alt=&quot;f:id:whoopsidaisies:20141128173940p:plain&quot; title=&quot;f:id:whoopsidaisies:20141128173940p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;最大まで拡大すると各画素の画素値が数字で表示される．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141128/20141128174024.png&quot; alt=&quot;f:id:whoopsidaisies:20141128174024p:plain&quot; title=&quot;f:id:whoopsidaisies:20141128174024p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;画素を右クリックしたら，その画素のアドレスのコピーとかも出来るもよう．&lt;/p&gt;&lt;p&gt;以上のようにOpenCVのMatの中の画像を簡単に確認できるので，Visual StudioでOpenCVを使う場合はかなり便利だと思う．&lt;/p&gt;&lt;p&gt;試してないけど&lt;a href=&quot;https://visualstudiogallery.msdn.microsoft.com/e682d542-7ef3-402c-b857-bbfba714f78d&quot;&gt;&amp;#x914D;&amp;#x5E03;&amp;#x30B5;&amp;#x30A4;&amp;#x30C8;&lt;/a&gt;の説明によると，cv::Mat_&lt;&gt;, CvMat, _IplImageなんかにも対応しているらしい．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C++" label="C++" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="Programming" label="Programming" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/7e92225bb76e1b9fd704ad5c8b3599bffa350f80/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141128%2F20141128165602.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>opencvで文字認識その１　Tesseractラッパ</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/11/12/003100"/>
        <id>hatenablog://entry/12921228815733154180</id>
        <published>2014-11-12T00:31:00+09:00</published>
        <updated>2014-11-12T00:31:00+09:00</updated>        <summary type="html">OpenCV3.0系から文字認識モジュールが搭載されるようなので使ってみる．現状の3.0 alphaや3.0 betaでは，文字認識モジュールはメインレポジトリに組み込まれておらず開発用レポジトリのopencv_contribの方に入っているようで，opencv_contribと一緒にOpenCVをビルドする必要がある． OpenCVの文字認識モジュール OpenCVのドキュメントによると，以下の２種類の文字認識方法があるらしい． オープンソースのOCRライブラリtesseract-ocrを呼び出す方法 隠れマルコフモデルによる認識方法 今回は，1の方法について試してみる． 文字認識モジュール…</summary>
        <content type="html">&lt;p&gt;&lt;a href=&quot;http://opencv.org/opencv-3-0-alpha.html&quot;&gt;OpenCV3.0&amp;#x7CFB;&amp;#x304B;&amp;#x3089;&amp;#x6587;&amp;#x5B57;&amp;#x8A8D;&amp;#x8B58;&amp;#x30E2;&amp;#x30B8;&amp;#x30E5;&amp;#x30FC;&amp;#x30EB;&amp;#x304C;&amp;#x642D;&amp;#x8F09;&amp;#x3055;&amp;#x308C;&amp;#x308B;&lt;/a&gt;ようなので使ってみる．現状の3.0 alphaや3.0 betaでは，文字認識モジュールはメインレポジトリに組み込まれておらず開発用レポジトリの&lt;a href=&quot;https://github.com/itseez/opencv_contrib&quot;&gt;opencv_contrib&lt;/a&gt;の方に入っているようで，opencv_contribと一緒にOpenCVをビルドする必要がある．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;OpenCVの文字認識モジュール&lt;/h3&gt;
    &lt;p&gt;&lt;a href=&quot;http://docs.opencv.org/trunk/modules/text/doc/ocr.html&quot;&gt;OpenCV&amp;#x306E;&amp;#x30C9;&amp;#x30AD;&amp;#x30E5;&amp;#x30E1;&amp;#x30F3;&amp;#x30C8;&lt;/a&gt;によると，以下の２種類の文字認識方法があるらしい．&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;オープンソースのOCRライブラリ&lt;a href=&quot;https://code.google.com/p/tesseract-ocr/&quot;&gt;tesseract-ocr&lt;/a&gt;を呼び出す方法&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cmp.felk.cvut.cz/~neumalu1/icdar2011_article.pdf&quot;&gt;&amp;#x96A0;&amp;#x308C;&amp;#x30DE;&amp;#x30EB;&amp;#x30B3;&amp;#x30D5;&amp;#x30E2;&amp;#x30C7;&amp;#x30EB;&amp;#x306B;&amp;#x3088;&amp;#x308B;&amp;#x8A8D;&amp;#x8B58;&amp;#x65B9;&amp;#x6CD5;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;今回は，1の方法について試してみる．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;文字認識モジュールの準備&lt;/h3&gt;
    
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;tesseract-ocrのダウンロード&lt;/h4&gt;
    &lt;p&gt;&lt;a href=&quot;https://code.google.com/p/tesseract-ocr/downloads/list&quot;&gt;https://code.google.com/p/tesseract-ocr/downloads/list&lt;/a&gt;からVC++からtesseract-ocrを呼び出す用のライブラリをダウンロード・解凍する．「tesseract-3.xx.xx-win32-lib-include-dirs.zip」って名前のやつ．今回は「&lt;a href=&quot;https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-3.02.02-win32-lib-include-dirs.zip&amp;can=2&amp;q=&quot;&gt;tesseract-3.02.02-win32-lib-include-dirs.zip&lt;/a&gt;」を使った．&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://code.google.com/p/tesseract-ocr/downloads/list&quot;&gt;https://code.google.com/p/tesseract-ocr/downloads/list&lt;/a&gt;からtesseract-ocr用の学習済みのデータファイルをダウンロードしておく．今回は英語で試すため「&lt;a href=&quot;https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-ocr-3.02.eng.tar.gz&amp;can=2&amp;q=&quot;&gt;tesseract-ocr-3.02.eng.tar.gz&lt;/a&gt;」をダウンロード・解凍する．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;opencv_contribのダウンロード&lt;/h4&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/itseez/opencv_contrib&quot;&gt;https://github.com/itseez/opencv_contrib&lt;/a&gt;からopencv_contribをダウンロード・解凍する．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;OpenCVのビルド&lt;/h4&gt;
    &lt;p&gt;CMakeを使ってビルドする．&lt;a href=&quot;http://www.buildinsider.net/small/opencv/02#cmake&quot;&gt;&amp;#x3053;&amp;#x3053;&amp;#x3089;&amp;#x3078;&amp;#x3093;&lt;/a&gt;を参考に．&lt;/p&gt;&lt;p&gt;「OPENCV_EXTRA_MODULES_PATH」パラメータの値を「(opencv_contribのパス)/modules」にセットしてConfigureする．&lt;/p&gt;&lt;p&gt;すると「Tesseract_INCLUDE_DIR」と「Tesseract_LIBRARY」というパラメータが出てくるので&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tesseract_INCLUDE_DIR ← (tesseract-ocrのパス)/include&lt;/li&gt;
&lt;li&gt;Tesseract_LIBRARY ← (tesseract-ocrのパス)/lib&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;とセットする．&lt;/p&gt;&lt;p&gt;以上の設定でGenerateしてOpenCVをビルドすると文字認識モジュールが組み込まれる．で，インストールする．&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;動作確認&lt;/h3&gt;
    &lt;p&gt;実際に画像を入力してやってみたソースコードと結果が以下．OpenCVのMat形式の画像を使って文字認識出来るため，&lt;a href=&quot;https://code.google.com/p/tesseract-ocr/wiki/APIExample&quot;&gt;tesseract-ocr&amp;#x306E;API&amp;#x76F4;&amp;#x63A5;&amp;#x53E9;&amp;#x304F;&lt;/a&gt;よりは使いやすいと思う．&lt;/p&gt;&lt;p&gt;追記）文字のかたまりの位置の出力が間違っていたためソースコードと結果画像を修正した．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;ソースコード&lt;/h5&gt;
    &lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/opencv.hpp&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/text.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; main()
{
	&lt;span class=&quot;synComment&quot;&gt;// 画像読み込み&lt;/span&gt;
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; image = cv::imread(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;moji.jpg&amp;quot;&lt;/span&gt;);
	&lt;span class=&quot;synComment&quot;&gt;// グレースケール化&lt;/span&gt;
	cv::Mat gray;
	cv::cvtColor(image, gray, COLOR_RGB2GRAY);
	&lt;span class=&quot;synComment&quot;&gt;// 文字認識クラスのインスタンス生成&lt;/span&gt;
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; ocr = cv::text::OCRTesseract::create(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;(言語データのパス)/tessdata&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;eng&amp;quot;&lt;/span&gt;);

	std::string text;
	std::vector&amp;lt;cv::Rect&amp;gt; boxes;
	std::vector&amp;lt;std::string&amp;gt; words;
	vector&amp;lt;&lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;&amp;gt; confidences;
	&lt;span class=&quot;synComment&quot;&gt;// 文字認識の実行&lt;/span&gt;
	ocr-&amp;gt;run(gray, text, &amp;amp;boxes, &amp;amp;words, &amp;amp;confidences);

	&lt;span class=&quot;synComment&quot;&gt;// 結果出力&lt;/span&gt;
	printf(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%s\n&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;, text.c_str());
	&lt;span class=&quot;synComment&quot;&gt;// 文字のかたまりごとに出力&lt;/span&gt;
	printf(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot; 文字      | 位置       | 大きさ     | 信頼度&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;);
	printf(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;-----------+------------+------------+----------&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;);
	&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; boxes.size(); i++)
	{
		printf(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%-10s&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt; | (&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%3d&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%3d&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;) | (&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%3d&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%3d&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;) | &lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%f\n&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;,
			words[i].c_str(),
			boxes[i].x, boxes[i].y,
			boxes[i].width, boxes[i].height,
			confidences[i]);
	}
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;実行結果&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20141112/20141112103657.png&quot; alt=&quot;f:id:whoopsidaisies:20141112103657p:plain&quot; title=&quot;f:id:whoopsidaisies:20141112103657p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;</content>        
        <category term="C++" label="C++" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="OpenCV 3.0" label="OpenCV 3.0" />
        
        <category term="Programming" label="Programming" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/7e96049c4e09553bea564106853f81c1d9764165/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20141112%2F20141112103657.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#で細線化 AForge.NET</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/09/15/094549"/>
        <id>hatenablog://entry/12921228815732929148</id>
        <published>2014-09-15T09:45:49+09:00</published>
        <updated>2014-09-15T09:45:49+09:00</updated>        <summary type="html">C#で画像の細線化処理を行って線画像を作成する．コンピュータビジョン等のライブラリであるAForge.NET Frameworkには，モルフォロジー処理が実装されているのでそれを利用する．細線化のアルゴリズムは以下のサイトあたりを参照． パターン認識の前処理に必要な二値画像の細線化：CodeZine 細線化アルゴリズム 画像処理ソリューション technotype AForge.NETのインストール Nuget経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「AForge」で検索．「AForge.Imaging」を選択してインストール…</summary>
        <content type="html">&lt;p&gt;C#で画像の細線化処理を行って線画像を作成する．コンピュータビジョン等のライブラリである&lt;a href=&quot;https://code.google.com/p/aforge/&quot;&gt;AForge.NET Framework&lt;/a&gt;には，&lt;a href=&quot;http://www.aforgenet.com/framework/features/morphology_filters.html&quot;&gt;&amp;#x30E2;&amp;#x30EB;&amp;#x30D5;&amp;#x30A9;&amp;#x30ED;&amp;#x30B8;&amp;#x30FC;&amp;#x51E6;&amp;#x7406;&amp;#x304C;&amp;#x5B9F;&amp;#x88C5;&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x308B;&lt;/a&gt;のでそれを利用する．&lt;/p&gt;&lt;p&gt;細線化のアルゴリズムは以下のサイトあたりを参照．&lt;br /&gt;
&lt;a href=&quot;http://codezine.jp/article/detail/98&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fcodezine.jp%2Farticle%2Fdetail%2F98&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://codezine.jp/article/detail/98&quot;&gt;&amp;#x30D1;&amp;#x30BF;&amp;#x30FC;&amp;#x30F3;&amp;#x8A8D;&amp;#x8B58;&amp;#x306E;&amp;#x524D;&amp;#x51E6;&amp;#x7406;&amp;#x306B;&amp;#x5FC5;&amp;#x8981;&amp;#x306A;&amp;#x4E8C;&amp;#x5024;&amp;#x753B;&amp;#x50CF;&amp;#x306E;&amp;#x7D30;&amp;#x7DDA;&amp;#x5316;&amp;#xFF1A;CodeZine&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://imagingsolution.blog107.fc2.com/blog-entry-138.html&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fimagingsolution.blog107.fc2.com%2Fblog-entry-138.html&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://imagingsolution.blog107.fc2.com/blog-entry-138.html&quot;&gt;&amp;#x7D30;&amp;#x7DDA;&amp;#x5316;&amp;#x30A2;&amp;#x30EB;&amp;#x30B4;&amp;#x30EA;&amp;#x30BA;&amp;#x30E0; &amp;#x753B;&amp;#x50CF;&amp;#x51E6;&amp;#x7406;&amp;#x30BD;&amp;#x30EA;&amp;#x30E5;&amp;#x30FC;&amp;#x30B7;&amp;#x30E7;&amp;#x30F3;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.technotype.net/tutorial/tutorial.php?fileId=%7BImage%20processing%7D&amp;sectionId=%7Bthinning-filter%7D&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.technotype.net%2Ftutorial%2Ftutorial.php%3FfileId%3D%257BImage%2520processing%257D%26sectionId%3D%257Bthinning-filter%257D&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.technotype.net/tutorial/tutorial.php?fileId=%7BImage%20processing%7D&amp;sectionId=%7Bthinning-filter%7D&quot;&gt;technotype&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;AForge.NETのインストール&lt;/h3&gt;
    &lt;p&gt;Nuget経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「AForge」で検索．「AForge.Imaging」を選択してインストール．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;p&gt;ヒット・ミス演算を行う&lt;a href=&quot;http://www.aforgenet.com/framework/docs/html/027a2813-1cf8-c91f-3d9c-365f577afd63.htm&quot;&gt;HitAndMiss&amp;#x30AF;&amp;#x30E9;&amp;#x30B9;&lt;/a&gt;を使う．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// using AForge.Imaging.Filters; をソースコードに書いておく&lt;/span&gt;

&lt;span class=&quot;synComment&quot;&gt;// 元画像の読み込み&lt;/span&gt;
var bmp = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Bitmap(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;moji.png&amp;quot;&lt;/span&gt;);
pictureBox1.Image = bmp;

&lt;span class=&quot;synComment&quot;&gt;// 二値化処理&lt;/span&gt;
var gray = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Grayscale(&lt;span class=&quot;synConstant&quot;&gt;0.2125&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0.7154&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0.0721&lt;/span&gt;).Apply(bmp);
var binary = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Threshold().Apply(gray);
pictureBox2.Image = binary;            
            
&lt;span class=&quot;synComment&quot;&gt;// 細線化用の８つのフィルタを作成&lt;/span&gt;
var filterSequence = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; FiltersSequence();
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; }, { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; }, { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; }, { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));
filterSequence.Add(&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; HitAndMiss(
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt;[,] { { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; }, { -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; } },
    HitAndMiss.Modes.Thinning));

&lt;span class=&quot;synComment&quot;&gt;// フィルタ処理の繰り返し回数を指定&lt;/span&gt;
var filter = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; FilterIterator(filterSequence, &lt;span class=&quot;synConstant&quot;&gt;20&lt;/span&gt;);

&lt;span class=&quot;synComment&quot;&gt;// 細線化処理の実行&lt;/span&gt;
var thinned = filter.Apply(binary);
pictureBox3.Image = thinned;
&lt;/pre&gt;&lt;p&gt;実行結果．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140915/20140915092901.png&quot; alt=&quot;f:id:whoopsidaisies:20140915092901p:plain&quot; title=&quot;f:id:whoopsidaisies:20140915092901p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="AForge.NET" label="AForge.NET" />
        
        <category term="C#" label="C#" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/f8ce697b47d85ee2720751ab38ffbb14c51e5f58/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140915%2F20140915092901.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
    <entry>
        <title>C#でGISデータ（shpファイル）を開く DotSpatialによる方法</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/09/15/011017"/>
        <id>hatenablog://entry/12921228815730750295</id>
        <published>2014-09-15T01:10:17+09:00</published>
        <updated>2014-09-15T01:10:17+09:00</updated>        <summary type="html">DotSpatialは.NET向けのオープンソースの地理情報システムライブラリである．これを使ってGISで用いられるshpファイル（とセットのshxファイルとdbfファイル）を読み込む． DotSpatialのインストール Nuget経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「DotSpatial」で検索．たくさん出てくるが，ここでは「DotSpatial.Controls」選択してインストール． Mapコントロールの追加 GISデータ表示用のコントロールが用意されているのでそれを使ってみる．まず，一度プロジェクトをビルドする．…</summary>
        <content type="html">&lt;p&gt;&lt;a href=&quot;http://dotspatial.codeplex.com/&quot;&gt;DotSpatial&lt;/a&gt;は.NET向けのオープンソースの地理情報システムライブラリである．これを使ってGISで用いられるshpファイル（とセットのshxファイルとdbfファイル）を読み込む．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;DotSpatialのインストール&lt;/h3&gt;
    &lt;p&gt;Nuget経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「DotSpatial」で検索．たくさん出てくるが，ここでは「DotSpatial.Controls」選択してインストール．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914212117.png&quot; alt=&quot;f:id:whoopsidaisies:20140914212117p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914212117p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Mapコントロールの追加&lt;/h3&gt;
    &lt;p&gt;GISデータ表示用のコントロールが用意されているのでそれを使ってみる．&lt;/p&gt;&lt;p&gt;まず，一度プロジェクトをビルドする．そうするとDotSpatialのDLLが実行ファイルのディレクトリにコピーされる．&lt;/p&gt;&lt;p&gt;ツールボックスの適当なところでクリックして「アイテムの選択(I)...」を選択．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914212749.png&quot; alt=&quot;f:id:whoopsidaisies:20140914212749p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914212749p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;「.NET Framework コンポーネント」タブの「参照(B)...」ボタンを押して，「(実行ファイルのパス)\DotSpatial.Controls.dll」を選択したらOK．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914212821.png&quot; alt=&quot;f:id:whoopsidaisies:20140914212821p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914212821p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914213930.png&quot; alt=&quot;f:id:whoopsidaisies:20140914213930p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914213930p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;そうすると「Map」というコントロールが追加されているのでフォームに追加する．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914213818.png&quot; alt=&quot;f:id:whoopsidaisies:20140914213818p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914213818p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;シェープファイルの読み込み&lt;/h3&gt;
    &lt;p&gt;シェープファイルは「&lt;a href=&quot;http://www.esrij.com/products/data/japan-shp/&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.esrij.com%2Fproducts%2Fdata%2Fjapan-shp%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.esrij.com/products/data/japan-shp/&quot;&gt;&amp;#x5168;&amp;#x56FD;&amp;#x5E02;&amp;#x533A;&amp;#x753A;&amp;#x6751;&amp;#x754C;&amp;#x30C7;&amp;#x30FC;&amp;#x30BF; | &amp;#x30C7;&amp;#x30FC;&amp;#x30BF;&amp;#x88FD;&amp;#x54C1;&amp;nbsp;|&amp;nbsp;&amp;#x88FD;&amp;#x54C1;&amp;nbsp;|&amp;nbsp;ESRI&amp;#x30B8;&amp;#x30E3;&amp;#x30D1;&amp;#x30F3;&amp;#x682A;&amp;#x5F0F;&amp;#x4F1A;&amp;#x793E;&lt;/a&gt;」でESRI Japanが配布している全国市区町村界データを使う．ダウンロードして解答したら以下のコードを追加する．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;map1.AddLayer(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;D:\Users\whoops\Downloads\japan_ver72\japan_ver72.shp&amp;quot;&lt;/span&gt;);
&lt;/pre&gt;&lt;p&gt;実行すると以下のように地図が表示される．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914214517.png&quot; alt=&quot;f:id:whoopsidaisies:20140914214517p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914214517p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;属性情報の表示 Infoモード&lt;/h3&gt;
    &lt;p&gt;上の状態だと地図が表示されるだけで何もできないためMapコントロールのモードを変える．以下のようにコードを追加してInfoモードにする．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;map1.AddLayer(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;D:\Users\whoops\Downloads\japan_ver72\japan_ver72.shp&amp;quot;&lt;/span&gt;);
map1.FunctionMode = DotSpatial.Controls.FunctionMode.Info;
&lt;/pre&gt;&lt;p&gt;これで実行すると以下のようにクリックした位置の市町村の情報を見れる．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140914/20140914214930.png&quot; alt=&quot;f:id:whoopsidaisies:20140914214930p:plain&quot; title=&quot;f:id:whoopsidaisies:20140914214930p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;領域の選択 Selectモード&lt;/h3&gt;
    &lt;p&gt;Selectモードににするとドラッグで領域指定できる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;map1.FunctionMode = DotSpatial.Controls.FunctionMode.Select;
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140915/20140915002531.png&quot; alt=&quot;f:id:whoopsidaisies:20140915002531p:plain&quot; title=&quot;f:id:whoopsidaisies:20140915002531p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;選択しただけだと何も表示されないので，TextBoxに選択された領域の情報を表示してみる．MAPコントロールのMouseUpイベントを追加して以下のコードを書き込む．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synType&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; map1_MouseUp(&lt;span class=&quot;synType&quot;&gt;object&lt;/span&gt; sender, MouseEventArgs e)
{
    textBox1.Text = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
    &lt;span class=&quot;synComment&quot;&gt;// MAPコントロールが保持しているレイヤーデータを取得&lt;/span&gt;
    var featureLayer = map1.Layers[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;] &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; DotSpatial.Symbology.FeatureLayer;
            
    &lt;span class=&quot;synComment&quot;&gt;// すべてのデータについてループ&lt;/span&gt;
    &lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; featureLayer.DrawnStates.Length; ++i)
    {
        &lt;span class=&quot;synComment&quot;&gt;// 選択されているかどうか判別&lt;/span&gt;
        &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; (featureLayer.DrawnStates[i].Selected == &lt;span class=&quot;synConstant&quot;&gt;true&lt;/span&gt;)
        {
            &lt;span class=&quot;synComment&quot;&gt;// i番目の属性情報取得&lt;/span&gt;
            var feature = featureLayer.FeatureSet.GetFeature(i);

            &lt;span class=&quot;synComment&quot;&gt;// DataRowからフィールド名でアクセス&lt;/span&gt;
            textBox1.Text += System.String.Format(
                &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;{0} : {1} {2} {3}人&amp;quot;&lt;/span&gt;,
                feature.DataRow[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;JCODE&amp;quot;&lt;/span&gt;],
                feature.DataRow[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;KEN&amp;quot;&lt;/span&gt;],
                feature.DataRow[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;SIKUCHOSON&amp;quot;&lt;/span&gt;],
                feature.DataRow[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;P_NUM&amp;quot;&lt;/span&gt;]
                )
                + System.Environment.NewLine;
        }
    }
}
&lt;/pre&gt;&lt;p&gt;選択されているかどうかはレイヤーデータの&lt;a href=&quot;http://www.nudoq.org/#!/Packages/DotSpatial.Symbology/DotSpatial.Symbology/LabelLayer/P/DrawnStates&quot;&gt;DrawnStates&lt;/a&gt;プロパティに格納されている．&lt;/p&gt;&lt;p&gt;属性情報は&lt;a href=&quot;https://dotspatial.codeplex.com/wikipage?title=DotSpatial.Data.Vectors.Beginner.FeatureSet&quot;&gt;FeatureSet&lt;/a&gt;プロパティに格納されていて&lt;a href=&quot;http://www.nudoq.org/#!/Packages/DotSpatial.Data/DotSpatial.Data/PolygonShapefile/M/GetFeature&quot;&gt;GetFeature&lt;/a&gt;メソッドで指定した番号のデータを取得できる．&lt;/p&gt;&lt;p&gt;各属性情報へは，DataRawにフィールド名を指定することで取得できる．このサンプルで使っているフィールド名は「&lt;a href=&quot;http://www.esrij.com/products/data/japan-shp/&quot;&gt;&amp;#x5168;&amp;#x56FD;&amp;#x5E02;&amp;#x533A;&amp;#x753A;&amp;#x6751;&amp;#x754C;&amp;#x30C7;&amp;#x30FC;&amp;#x30BF; | &amp;#x30C7;&amp;#x30FC;&amp;#x30BF;&amp;#x88FD;&amp;#x54C1;&amp;nbsp;|&amp;nbsp;&amp;#x88FD;&amp;#x54C1;&amp;nbsp;|&amp;nbsp;ESRI&amp;#x30B8;&amp;#x30E3;&amp;#x30D1;&amp;#x30F3;&amp;#x682A;&amp;#x5F0F;&amp;#x4F1A;&amp;#x793E;&lt;/a&gt;」を参照．&lt;/p&gt;&lt;p&gt;実行してドラッグで領域選択すると以下のようにTextBoxに情報が表示される．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140915/20140915004858.png&quot; alt=&quot;f:id:whoopsidaisies:20140915004858p:plain&quot; title=&quot;f:id:whoopsidaisies:20140915004858p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;MAPコントロールなしで読み込み&lt;/h3&gt;
    &lt;p&gt;MAPコントロールを配置しなくても&lt;a href=&quot;http://www.nudoq.org/#!/Packages/DotSpatial.Data/DotSpatial.Data/DataManager&quot;&gt;DataManager&lt;/a&gt;クラスの&lt;a href=&quot;http://www.nudoq.org/#!/Packages/DotSpatial.Data/DotSpatial.Data/DataManager/M/OpenFile&quot;&gt;OpenFile&lt;/a&gt;メソッドを使えばシェープファイルは読み込める．&lt;/p&gt;&lt;p&gt;以下にシェープファイルを読み込んで，0番目のデータの座標を出力するコードを載せる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// シェープファイルの読み込み&lt;/span&gt;
var layer = DotSpatial.Data.DataManager.DefaultDataManager.OpenFile(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;D:\Users\whoops\Downloads\japan_ver72\japan_ver72.shp&amp;quot;&lt;/span&gt;) 
    &lt;span class=&quot;synStatement&quot;&gt;as&lt;/span&gt; DotSpatial.Data.FeatureSet;
&lt;span class=&quot;synComment&quot;&gt;// 0番目のデータの座標を表示&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (var cordinate &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; layer.GetFeature(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;).Coordinates)
{
    Console.WriteLine(cordinate.ToString());
}
&lt;/pre&gt;&lt;p&gt;実行結果&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140915/20140915010455.png&quot; alt=&quot;f:id:whoopsidaisies:20140915010455p:plain&quot; title=&quot;f:id:whoopsidaisies:20140915010455p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;コントロールを使わない方法だけを使う場合NuGetで「DotSpatial.Data」をインストールすればできる．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="NuGet" label="NuGet" />
        
        <category term=".NET" label=".NET" />
        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/fb8b8277a990340396b3c024e7a5f13541260db9/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140915%2F20140915004858.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>SVGアニメーションで初音ミクの一筆書き</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/09/13/222226"/>
        <id>hatenablog://entry/12921228815732826994</id>
        <published>2014-09-13T22:22:26+09:00</published>
        <updated>2014-09-13T22:22:26+09:00</updated>        <summary type="html">SVGによるアニメーションの勉強メモと，作った初音ミクの一筆書きアニメーション．アニメーションをSVGのanimateMotion要素と，CSSのanimationプロパティを使った．本当はCSS使わないでやりたかったのだけどそれだと面倒くさそうだったのでCSSも使った．元画像は以下のサイトから持ってきた． piapro(ピアプロ)|イラスト「一筆書きで 初音ミクを 描きました」 以下が作ったアニメーション．SVGとCSSのアニメーションの同期の取り方がわからなかったので，読み込みの度にタイミングが変わってしまう． ※SVGファイルを置くのに借りていたレンタルサーバーの期限が切れてしまったため…</summary>
        <content type="html">&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;によるアニメーションの勉強メモと，作った&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%BD%E9%B2%BB%A5%DF%A5%AF&quot;&gt;初音ミク&lt;/a&gt;の一筆書きアニメーション．&lt;/p&gt;&lt;p&gt;アニメーションを&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;のanimateMotion要素と，&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt;のanimationプロパティを使った．本当は&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt;使わないでやりたかったのだけどそれだと面倒くさそうだったので&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt;も使った．&lt;/p&gt;&lt;p&gt;元画像は以下のサイトから持ってきた．&lt;br /&gt;
&lt;a href=&quot;http://piapro.jp/t/zL1d&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fpiapro.jp%2Ft%2FzL1d&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://piapro.jp/t/zL1d&quot;&gt;piapro(&amp;#x30D4;&amp;#x30A2;&amp;#x30D7;&amp;#x30ED;)|&amp;#x30A4;&amp;#x30E9;&amp;#x30B9;&amp;#x30C8;&amp;#x300C;&amp;#x4E00;&amp;#x7B46;&amp;#x66F8;&amp;#x304D;&amp;#x3067; &amp;#x521D;&amp;#x97F3;&amp;#x30DF;&amp;#x30AF;&amp;#x3092; &amp;#x63CF;&amp;#x304D;&amp;#x307E;&amp;#x3057;&amp;#x305F;&amp;#x300D;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;del&gt;&lt;br /&gt;
以下が作ったアニメーション．&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;と&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt;のアニメーションの同期の取り方がわからなかったので，読み込みの度にタイミングが変わってしまう．&lt;/del&gt;&lt;br /&gt;
※&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;ファイルを置くのに借りていた&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%EC%A5%F3%A5%BF%A5%EB%A5%B5%A1%BC%A5%D0%A1%BC&quot;&gt;レンタルサーバー&lt;/a&gt;の期限が切れてしまったため、暇なとき別のところにアップロードしなおします。&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt; animateMotion要素&lt;/h3&gt;
    &lt;p&gt;赤い円を移動させるのには，&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;の&lt;a href=&quot;https://developer.mozilla.org/ja/docs/Web/SVG/Element/animateMotion&quot;&gt;animateMotion&amp;#x8981;&amp;#x7D20;&lt;/a&gt;を使った．&lt;/p&gt;&lt;p&gt;animateMotion要素を用いると，図形をpathで指定した任意の曲線に沿って移動させることが出来る．また，&lt;a href=&quot;https://developer.mozilla.org/ja/docs/Web/SVG/Element/mpath&quot;&gt;mpath&amp;#x8981;&amp;#x7D20;&lt;/a&gt;によって以下のようにpathの参照が可能．&lt;/p&gt;

    &lt;blockquote cite=&quot;https://developer.mozilla.org/ja/docs/Web/SVG/Element/animateMotion&quot;&gt;
        &lt;pre class=&quot;code lang-xml&quot; data-lang=&quot;xml&quot; data-unlink&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;path &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;d&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;M10,110 A120,120 -45 0,1 110 10 A120,120 -45 0,1 10,110&amp;quot;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;stroke&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;lightgrey&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;stroke-width&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;2&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;fill&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;theMotionPath&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;circle &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;cx&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;cy&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;110&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;r&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;3&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;fill&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;lightgrey&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;  /&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;circle &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;cx&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;110&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;cy&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;r&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;3&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;fill&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;lightgrey&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;  /&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synComment&quot;&gt;&amp;lt;!-- Here is a red circle which will be moved along the motion path. --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;circle &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;cx&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;cy&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;r&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;5&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;fill&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;synComment&quot;&gt;&amp;lt;!-- Define the motion path animation --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;animateMotion &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;dur&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;6s&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;repeatCount&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;indefinite&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
       &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;mpath &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;xlink&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;#theMotionPath&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/animateMotion&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/circle&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
        &lt;cite&gt;&lt;a href=&quot;https://developer.mozilla.org/ja/docs/Web/SVG/Element/animateMotion&quot;&gt;animateMotion - SVG | MDN&lt;/a&gt;&lt;/cite&gt;
    &lt;/blockquote&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt; animate要素&lt;/h3&gt;
    &lt;p&gt;線を描いていく様子は，&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt;の&lt;a href=&quot;http://css-tricks.com/svg-line-animation-works/&quot;&gt;animate&amp;#x8981;&amp;#x7D20;&amp;#x3092;&amp;#x4F7F;&amp;#x3063;&amp;#x3066;&amp;#x7834;&amp;#x7DDA;&amp;#x306E;&amp;#x9593;&amp;#x9694;&amp;#x3092;&amp;#x5909;&amp;#x3048;&amp;#x308B;&amp;#x65B9;&amp;#x6CD5;&lt;/a&gt;を使った．&lt;br /&gt;
破線の間隔が変わることで線が伸びて行っているように見えるようだ．&lt;/p&gt;

    &lt;blockquote cite=&quot;http://css-tricks.com/svg-line-animation-works/&quot;&gt;
        &lt;p&gt;&lt;img src=&quot;http://cdn.css-tricks.com/wp-content/uploads/2014/02/animate-stroke-full.gif&quot;&gt;&lt;/img&gt;&lt;/p&gt;

        &lt;cite&gt;&lt;a href=&quot;http://css-tricks.com/svg-line-animation-works/&quot;&gt;How SVG Line Animation Works | CSS-Tricks&lt;/a&gt;&lt;/cite&gt;
    &lt;/blockquote&gt;
&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSS&quot;&gt;CSS&lt;/a&gt;に以下のように描いてやるといいようだが，stroke-dasharrayやstroke-dashoffsetの値を線の長さくらいにしなくてはならないらしく少し面倒．&lt;/p&gt;
&lt;pre class=&quot;code lang-css&quot; data-lang=&quot;css&quot; data-unlink&gt;path &lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt;
  stroke-dasharray: &lt;span class=&quot;synConstant&quot;&gt;1000&lt;/span&gt;;
  stroke-dashoffset: &lt;span class=&quot;synConstant&quot;&gt;1000&lt;/span&gt;;
  animation: dash &lt;span class=&quot;synConstant&quot;&gt;5s&lt;/span&gt; linear forwards;
&lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;

@keyframes dash &lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt;
  to {
    stroke-dashoffset: &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;;
  &lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;synError&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;d3.jsで作成&lt;/h3&gt;
    &lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%BD%E9%B2%BB%A5%DF%A5%AF&quot;&gt;初音ミク&lt;/a&gt;の座標データは画像からこつこつと抽出した．以下からダウンロード可能．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.site-station.net/blog/miku.csv&quot;&gt;http://whoopsidaisies.site-station.net/blog/miku.csv&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;直打ちでもよかったが，せっかくなのでd3.jsで&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/CSV&quot;&gt;CSV&lt;/a&gt;ファイルを読み込んで&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/SVG&quot;&gt;SVG&lt;/a&gt;を吐き出した．&lt;/p&gt;
&lt;pre class=&quot;code lang-javascript&quot; data-lang=&quot;javascript&quot; data-unlink&gt;d3.csv(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;miku2.csv&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;function&lt;/span&gt; (data) &lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;synIdentifier&quot;&gt;var&lt;/span&gt; line = d3.svg.line()
        .x(&lt;span class=&quot;synIdentifier&quot;&gt;function&lt;/span&gt; (d) &lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; Math.round(d.x * 10) / 10; &lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;)
        .y(&lt;span class=&quot;synIdentifier&quot;&gt;function&lt;/span&gt; (d) &lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; Math.round(d.y * 10) / 10; &lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;)
        .interpolate(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;linear&amp;quot;&lt;/span&gt;);

    &lt;span class=&quot;synIdentifier&quot;&gt;var&lt;/span&gt; svg = d3.select(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;body&amp;quot;&lt;/span&gt;).append(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;svg&amp;quot;&lt;/span&gt;).attr(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;width&amp;quot;&lt;/span&gt;, 700).attr(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;height&amp;quot;&lt;/span&gt;, 900);
        
    &lt;span class=&quot;synIdentifier&quot;&gt;var&lt;/span&gt; path = svg.append(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;path&amp;quot;&lt;/span&gt;)
        .attr(&lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;d&amp;quot;&lt;/span&gt;: line(data),
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;stroke&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;black&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;stroke-width&amp;quot;&lt;/span&gt;: 2,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;fill&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;none&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;mikupath&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;);

    svg.append(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;circle&amp;quot;&lt;/span&gt;)
        .attr(&lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;cx&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;cy&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;r&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;5&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;fill&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;)
        .append(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;animateMotion&amp;quot;&lt;/span&gt;)
        .attr(&lt;span class=&quot;synIdentifier&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;dur&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;20s&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;repeatCount&amp;quot;&lt;/span&gt;: &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;indefinite&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;)
        .append(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;mpath&amp;quot;&lt;/span&gt;)
        .attr(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;xlink:href&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;#mikupath&amp;quot;&lt;/span&gt;);
&lt;span class=&quot;synIdentifier&quot;&gt;}&lt;/span&gt;);
&lt;/pre&gt;&lt;p&gt;&lt;del&gt;&lt;br /&gt;
&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%BD%A1%BC%A5%B9%A5%B3%A1%BC%A5%C9&quot;&gt;ソースコード&lt;/a&gt;全文は以下．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.site-station.net/blog/mikuanimation2.html&quot;&gt;http://whoopsidaisies.site-station.net/blog/mikuanimation2.html&lt;/a&gt;&lt;br /&gt;
&lt;/del&gt;&lt;br /&gt;
&lt;del&gt;&lt;br /&gt;
実行後のhtmlは以下．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.site-station.net/blog/mikuanimation.html&quot;&gt;http://whoopsidaisies.site-station.net/blog/mikuanimation.html&lt;/a&gt;&lt;br /&gt;
&lt;/del&gt;&lt;br /&gt;
※&lt;a class=&quot;keyword&quot; href=&quot;http://d.hatena.ne.jp/keyword/%A5%EC%A5%F3%A5%BF%A5%EB%A5%B5%A1%BC%A5%D0%A1%BC&quot;&gt;レンタルサーバー&lt;/a&gt;の期限が切れてしまったため、暇なとき別のところにアップロードしなおします。&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="d3.js" label="d3.js" />
        
        <category term="SVG" label="SVG" />
        
        <category term="javascript" label="javascript" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/d2e294305ba335b34b1097edc65818fcd6237c9d/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140913%2F20140913212241.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>PowerPointのオートシェイプで好きな関数の曲線を作る　C# NetOfficeによる方法</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/09/11/124318"/>
        <id>hatenablog://entry/12921228815732529471</id>
        <published>2014-09-11T12:43:18+09:00</published>
        <updated>2014-09-11T12:43:18+09:00</updated>        <summary type="html">sin(x)/xのオートシェイプオートシェイプできれいな波形を作りたいときがたまにあるのだけど，C#を使って上の画像みたいにsin(x)/xのオートシェイプをわりときれいに作れたので手順をまとめる．試した環境はPowerPoint2010とVisual Studio 2013．バージョンが違うと少し変わる可能性はあると思う．（わざわざC#でやらずともVBAマクロでも同じことは出来るけど，VBAは苦手なのでC#でやる．VBAでのやり方も後述します）出来上がったPowerPointファイルを以下からダウンロードできるようにしておいた． sinc.pptx - Google ドライブ NetOffi…</summary>
        <content type="html">&lt;p&gt;&lt;figure&gt;&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140911/20140911101713.png&quot; alt=&quot;f:id:whoopsidaisies:20140911101713p:plain&quot; title=&quot;f:id:whoopsidaisies:20140911101713p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;figcaption align=&quot;center&quot;&gt;sin(x)/xのオートシェイプ&lt;/figcaption&gt;&lt;/figure&gt;&lt;/p&gt;&lt;p&gt;オートシェイプできれいな波形を作りたいときがたまにあるのだけど，C#を使って上の画像みたいにsin(x)/xのオートシェイプをわりときれいに作れたので手順をまとめる．&lt;/p&gt;&lt;p&gt;試した環境はPowerPoint2010とVisual Studio 2013．バージョンが違うと少し変わる可能性はあると思う．（わざわざC#でやらずともVBAマクロでも同じことは出来るけど，VBAは苦手なのでC#でやる．VBAでのやり方も後述します）&lt;/p&gt;&lt;p&gt;出来上がったPowerPointファイルを以下からダウンロードできるようにしておいた．&lt;br /&gt;
&lt;a href=&quot;https://docs.google.com/file/d/0B8I67X8vyAXOSFJLaTlIOGhsMGM/edit&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=https%3A%2F%2Fdocs.google.com%2Ffile%2Fd%2F0B8I67X8vyAXOSFJLaTlIOGhsMGM%2Fedit&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://docs.google.com/file/d/0B8I67X8vyAXOSFJLaTlIOGhsMGM/edit&quot;&gt;sinc.pptx - Google &amp;#x30C9;&amp;#x30E9;&amp;#x30A4;&amp;#x30D6;&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;NetOffice.PowerPointのインストール&lt;/h3&gt;
    &lt;p&gt;以前「&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/06/19/101032&quot;&gt;C#&amp;#x3067;Excel&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x3092;&amp;#x4F5C;&amp;#x6210;&amp;#x30FB;&amp;#x30B0;&amp;#x30E9;&amp;#x30D5;&amp;#x3092;&amp;#x633F;&amp;#x5165;&amp;#x3059;&amp;#x308B; NetOffice&amp;#x306B;&amp;#x3088;&amp;#x308B;&amp;#x65B9;&amp;#x6CD5; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;」で紹介した，&lt;a href=&quot;http://netoffice.codeplex.com/&quot;&gt;NetOffice&lt;/a&gt;という.NET用のライブラリを使うとPowerPoint等にアクセスして色々出来るのでそれを利用する．&lt;/p&gt;&lt;p&gt;NetOfficeはNuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「NetOffice.PowerPoint」を検索してインストール．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;p&gt;以下にソースコードを載せる．スライドを作って&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/office/ff744765(v=office.15).aspx&quot;&gt;AddCurve&lt;/a&gt;メソッドで曲線を追加しているだけである．&lt;/p&gt;&lt;p&gt;AddCurveメソッドの引数として，float[(点の数),2]に座標を格納して渡す．この点の座標を元にベジェ曲線を描くようである．&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/office/ff744765(v=office.15).aspx&quot;&gt;&amp;#x70B9;&amp;#x306E;&amp;#x6570;&amp;#x306F;3n+1&amp;#x500B;&lt;/a&gt;にしないと止まるので注意．&lt;/p&gt;&lt;p&gt;点の座標はスライドの左上が(0,0)でピクセルで指定する．スライドのオブジェクトの&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/office/ff745135(v=office.15).aspx&quot;&gt;PageSetup&lt;/a&gt;プロパティにスライドの幅と高さが格納されているのでそれを元に大きさを調整した．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synType&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; Main(&lt;span class=&quot;synType&quot;&gt;string&lt;/span&gt;[] args)
{
    &lt;span class=&quot;synComment&quot;&gt;// パワーポイントを開く&lt;/span&gt;
    &lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var app = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; NetOffice.PowerPointApi.Application())
    {
        &lt;span class=&quot;synComment&quot;&gt;// プレゼンテーションの作成&lt;/span&gt;
        var presentation = app.Presentations.Add();
        &lt;span class=&quot;synComment&quot;&gt;// スライドの追加&lt;/span&gt;
        var slide = presentation.Slides.Add(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, NetOffice.PowerPointApi.Enums.PpSlideLayout.ppLayoutBlank);

        &lt;span class=&quot;synComment&quot;&gt;// sin(x)/xの座標を得る&lt;/span&gt;
        var sinc = GetSinc(presentation.PageSetup.SlideWidth, presentation.PageSetup.SlideHeight);

        &lt;span class=&quot;synComment&quot;&gt;// 座標からベジェ曲線を描画する&lt;/span&gt;
        &lt;span class=&quot;synComment&quot;&gt;// 引数はfloatの二次元配列．座標の数は6n+1個じゃないといけないため注意．&lt;/span&gt;
        slide.Shapes.AddCurve(sinc);

        &lt;span class=&quot;synComment&quot;&gt;// プレゼンテーションの保存&lt;/span&gt;
        presentation.SaveAs(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;D:\a.pptx&amp;quot;&lt;/span&gt;);
        &lt;span class=&quot;synComment&quot;&gt;// プレゼンテーションファイルを閉じる&lt;/span&gt;
        presentation.Close();
        &lt;span class=&quot;synComment&quot;&gt;// パワーポイントの終了　作成したファイル以外も閉じられるので注意&lt;/span&gt;
        &lt;span class=&quot;synComment&quot;&gt;//app.Quit();&lt;/span&gt;
    }
}

&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// sin(x)/x関数の座標をスライドの大きさに合わせて拡大，&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;slideWidth&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;スライドの幅&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;slideHeight&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;スライドの高さ&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;sin(x)/x関数を描くための点の座標&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;[,] GetSinc(&lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt; slideWidth, &lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt; slideHeight)
{
    &lt;span class=&quot;synComment&quot;&gt;// xが-4π～4πまでのsin(x)/xを求める．601点．&lt;/span&gt;
    var xs = Enumerable.Range(-&lt;span class=&quot;synConstant&quot;&gt;300&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;601&lt;/span&gt;).Select(x =&amp;gt; x * &lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt; * Math.PI / &lt;span class=&quot;synConstant&quot;&gt;300&lt;/span&gt;);
    var ys = xs.Select(x =&amp;gt; x != &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; ? Math.Sin(x) / x : &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;);

    &lt;span class=&quot;synComment&quot;&gt;// PowerPointのスライドのサイズに合わせて移動・拡大をする&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;// 中心座標&lt;/span&gt;
    var cx = slideWidth / &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;;
    var cy = slideHeight / &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;;
    &lt;span class=&quot;synComment&quot;&gt;// オブジェクトのだいたいの大きさ&lt;/span&gt;
    var width = slideWidth * &lt;span class=&quot;synConstant&quot;&gt;0.8&lt;/span&gt;;
    var height = slideHeight * &lt;span class=&quot;synConstant&quot;&gt;0.8&lt;/span&gt;;
    var pptXs = xs.Select(x =&amp;gt; x / (&lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt; * Math.PI) * width / &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; + cx).ToArray();
    var pptYs = ys.Select(y =&amp;gt; -y * height / &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; + cy).ToArray();

    &lt;span class=&quot;synComment&quot;&gt;// AddCurveメソッドに渡すためにfloatの2次元配列に代入する&lt;/span&gt;
    var sinc = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;[pptXs.Length, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;];
    &lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; pptXs.Length; ++ i)
    {
        sinc[i, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;] = (&lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;)pptXs[i];
        sinc[i, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;] = (&lt;span class=&quot;synType&quot;&gt;float&lt;/span&gt;)pptYs[i];
    }
    &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; sinc;
}
&lt;/pre&gt;&lt;p&gt;実行すると，記事の最初の画像のpptxファイルが作成される．GetSincメソッドの部分を適当な座標を格納をするように変えれば自分の好きな曲線を引ける．&lt;/p&gt;&lt;p&gt;ちなみに出来た曲線はオートシェイプなので，以下の画像のように線の太さとか種類とか色とかも簡単に変えられる．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140911/20140911115617.png&quot; alt=&quot;f:id:whoopsidaisies:20140911115617p:plain&quot; title=&quot;f:id:whoopsidaisies:20140911115617p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
拡大してもきれい．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140911/20140911115623.png&quot; alt=&quot;f:id:whoopsidaisies:20140911115623p:plain&quot; title=&quot;f:id:whoopsidaisies:20140911115623p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;VBAマクロでのやり方&lt;/h3&gt;
    &lt;p&gt;記事の最初にも述べたが，C#を使わずともVBAマクロで同じことが出来る．以下に参考になるコードを載せる（&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/office/ff744765(v=office.15).aspx&quot;&gt;&amp;#x3053;&amp;#x3053;&lt;/a&gt;のサンプル見やすくしただけだけど）．&lt;/p&gt;&lt;p&gt;これの点の座標を引きたい曲線の座標にしてやればOK.&lt;/p&gt;
&lt;pre class=&quot;code lang-vb&quot; data-lang=&quot;vb&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;Sub&lt;/span&gt; DrawCurve&lt;span class=&quot;synStatement&quot;&gt;()&lt;/span&gt;
   &lt;span class=&quot;synComment&quot;&gt; &#39; 1枚目のスライドのオブジェクトを得る&lt;/span&gt;
    &lt;span class=&quot;synStatement&quot;&gt;Dim&lt;/span&gt; slide &lt;span class=&quot;synStatement&quot;&gt;As&lt;/span&gt; PowerPoint&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;slide
    &lt;span class=&quot;synStatement&quot;&gt;Set&lt;/span&gt; slide &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; ActivePresentation&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;Slides&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt;
       
   &lt;span class=&quot;synComment&quot;&gt; &#39; ベジェ曲線を引くための点の座標を配列に格納&lt;/span&gt;
   &lt;span class=&quot;synComment&quot;&gt; &#39; ここの座標の値を適当に変えてやれば好きな曲線が引ける&lt;/span&gt;
    &lt;span class=&quot;synStatement&quot;&gt;Dim&lt;/span&gt; points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;To&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;To&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;Single&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;72&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;72&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;100&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;40&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;20&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;50&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;90&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;120&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;60&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;30&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;150&lt;/span&gt;
    points&lt;span class=&quot;synStatement&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;90&lt;/span&gt;
    
   &lt;span class=&quot;synComment&quot;&gt; &#39; 曲線の追加&lt;/span&gt;
    slide&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;Shapes&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;AddCurve SafeArrayOfPoints:&lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt;points
&lt;span class=&quot;synStatement&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;Sub&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content>        
        <category term=".NET" label=".NET" />
        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term="VBA" label="VBA" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/404a45618cb4aa6c8412b6af5af8fb4b0f44ebd4/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140911%2F20140911101713.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>OpenCVでDeepFlow</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/08/21/221642"/>
        <id>hatenablog://entry/12921228815730868159</id>
        <published>2014-08-21T22:16:42+09:00</published>
        <updated>2014-08-21T22:16:42+09:00</updated>        <summary type="html">opencv_contribを見てたら，DeepFlowというオプティカルフローのアルゴリズムが実装されていたので勉強ついでに使ってみる． DeepFlow DeepFlowはコンピュータビジョンの分野では有名な国際学会ICCV2013でWeinzaepfelらによって発表されたアルゴリズムである． HAL - INRIA :: [hal-00873592, version 1] DeepFlow: Large displacement optical flow with deep matchingDeepFlowではDeep Matchingという画像のマッチング手法（これも同論文内で提案さ…</summary>
        <content type="html">&lt;p&gt;&lt;a href=&quot;http://code.opencv.org/projects/opencv/wiki/ChangeLog&quot;&gt;opencv_contrib&lt;/a&gt;を見てたら，&lt;a href=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;DeepFlow&lt;/a&gt;というオプティカルフローのアルゴリズムが実装されていたので勉強ついでに使ってみる．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;DeepFlow&lt;/h3&gt;
    &lt;p&gt;DeepFlowはコンピュータビジョンの分野では有名な国際学会&lt;a href=&quot;http://www.iccv2013.org/&quot;&gt;ICCV2013&lt;/a&gt;でWeinzaepfelらによって発表されたアルゴリズムである．&lt;br /&gt;
&lt;a href=&quot;http://hal.inria.fr/hal-00873592&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fhal.inria.fr%2Fhal-00873592&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://hal.inria.fr/hal-00873592&quot;&gt;HAL - INRIA :: [hal-00873592, version 1] DeepFlow: Large displacement optical flow with deep matching&lt;/a&gt;&lt;/p&gt;&lt;p&gt;DeepFlowではDeep Matchingという画像のマッチング手法（これも同論文内で提案されている）を用いてオプティカルフローを求めている．&lt;/p&gt;&lt;p&gt;以下の画像にアルゴリズムの全体像がまとめられている．&lt;/p&gt;

    &lt;blockquote cite=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;
        &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140821/20140821140023.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140821140023j:plain&quot; title=&quot;f:id:whoopsidaisies:20140821140023j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

        &lt;cite&gt;&lt;a href=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Flear.inrialpes.fr%2Fsrc%2Fdeepmatching%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;LEAR - DeepMatchingFlow&lt;/a&gt;&lt;/cite&gt;
    &lt;/blockquote&gt;
&lt;p&gt;パワーポイントの資料は&lt;a href=&quot;http://lear.inrialpes.fr/people/pweinzae/files/DeepFlow_iccv2013_slides.ppt&quot;&gt;&amp;#x3053;&amp;#x3061;&amp;#x3089;&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;Deep Matching&lt;/h4&gt;
    &lt;p&gt;&lt;a href=&quot;http://lear.inrialpes.fr/people/revaud/&quot;&gt;Deep Matching&lt;/a&gt;では，畳み込み，プーリング，サブサンプリングを繰り返しすことで，画像間のQuasi-Denseなマッチング（日本語でなんていうかわからない．準密？）を求める．&lt;/p&gt;&lt;p&gt;Deep Learningで注目を集めているConvolutional Neural Networks（CNN）に似たアプローチとなっている．&lt;/p&gt;&lt;p&gt;Deep Matchingを使うと以下のように非剛体のマッチングもうまく出来るようである．&lt;/p&gt;

    &lt;blockquote cite=&quot;http://lear.inrialpes.fr/people/revaud/&quot;&gt;
        &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140821/20140821152916.png&quot; alt=&quot;f:id:whoopsidaisies:20140821152916p:plain&quot; title=&quot;f:id:whoopsidaisies:20140821152916p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140821/20140821152927.png&quot; alt=&quot;f:id:whoopsidaisies:20140821152927p:plain&quot; title=&quot;f:id:whoopsidaisies:20140821152927p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

        &lt;cite&gt;&lt;a href=&quot;http://lear.inrialpes.fr/people/revaud/&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Flear.inrialpes.fr%2Fpeople%2Frevaud%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://lear.inrialpes.fr/people/revaud/&quot;&gt;Jerome Revaud&lt;/a&gt;&lt;/cite&gt;
    &lt;/blockquote&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;オプティカルフロー&lt;/h3&gt;
    &lt;p&gt;DeepFlowでは，時間的輝度勾配と空間的輝度勾配の拘束条件に加えて，Deep Matchingで求めた対応とオプティカルフローとの差異も拘束条件として目的関数に入れることで，密でかつ大きな動きにも強いオプティカルフローを得るようである．&lt;/p&gt;&lt;p&gt;目的関数の最小化は&lt;a href=&quot;http://ja.wikipedia.org/wiki/SOR%E6%B3%95&quot;&gt;SOR&amp;#x6CD5;&lt;/a&gt;という反復法で行っているようである．&lt;/p&gt;&lt;p&gt;DeepFlowで以下の画像みたいな感じにマッチングとオプティカルフローが得られるらしい．&lt;/p&gt;

    &lt;blockquote cite=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;
        &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140821/20140821180059.png&quot; alt=&quot;f:id:whoopsidaisies:20140821180059p:plain&quot; title=&quot;f:id:whoopsidaisies:20140821180059p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

        &lt;cite&gt;&lt;a href=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Flear.inrialpes.fr%2Fsrc%2Fdeepmatching%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://lear.inrialpes.fr/src/deepmatching/&quot;&gt;LEAR - DeepMatchingFlow&lt;/a&gt;&lt;/cite&gt;
    &lt;/blockquote&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;OpenCVで動かしてみる&lt;/h3&gt;
    &lt;p&gt;DeepFlowは2014/8/21現在&lt;a href=&quot;https://github.com/Itseez/opencv_contrib&quot;&gt;opencv_contrib&lt;/a&gt;に入っているが，opencv_contribは開発用リポジトリらしいので自己責任で．&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/Itseez/opencv_contrib&quot;&gt;&amp;#x3053;&amp;#x3053;&lt;/a&gt;からソースを落としてきて，OpenCVのCMakeのオプションで「OPENCV_EXTRA_MODULES_PATH」を「（opencv_contribのパス）/modules」としてgenerate，ビルドしてやるとOpenCVにopencv_contrib内のモジュールが組み込まれる．&lt;/p&gt;&lt;p&gt;実際にDeepFlowを動かしてみたソースコードは以下．&lt;br /&gt;
DeepFlowのパラメータは&lt;a href=&quot;http://docs.opencv.org/3.0-alpha/modules/optflow/doc/dense_optflow.html?highlight=deepflow#optflow::OpticalFlowDeepFlow: public DenseOpticalFlow&quot;&gt;&amp;#x3053;&amp;#x3053;&lt;/a&gt;を参照．&lt;/p&gt;
&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/opencv.hpp&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/optflow.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; main()
{
	&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; cv;

	&lt;span class=&quot;synComment&quot;&gt;// DeepFlow計算用のインスタンスを生成&lt;/span&gt;
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; deepflow = optflow::createOptFlow_DeepFlow();
	&lt;span class=&quot;synComment&quot;&gt;// 動画読み込み&lt;/span&gt;
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; capture = VideoCapture(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;video.mp4&amp;quot;&lt;/span&gt;);
	
	&lt;span class=&quot;synComment&quot;&gt;// 前のフレーム保存&lt;/span&gt;
	&lt;span class=&quot;synComment&quot;&gt;// まだグレースケールしか対応してないようなので変換&lt;/span&gt;
	Mat prev, tmp;
	capture &amp;gt;&amp;gt; tmp;
	cvtColor(tmp, prev, COLOR_RGB2GRAY);

	&lt;span class=&quot;synStatement&quot;&gt;while&lt;/span&gt; (cv::waitKey(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;) == -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;)
	{
		Mat curr;
		capture &amp;gt;&amp;gt; tmp;
		&lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; (tmp.empty())
			&lt;span class=&quot;synStatement&quot;&gt;break&lt;/span&gt;;
		cvtColor(tmp, curr, COLOR_RGB2GRAY);

		&lt;span class=&quot;synComment&quot;&gt;// オプティカルフローの計算&lt;/span&gt;
		Mat flow;
		deepflow-&amp;gt;calc(prev, curr, flow);

		&lt;span class=&quot;synComment&quot;&gt;// 表示するようにX成分とY成分に分解&lt;/span&gt;
		Mat flowXY[&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;];
		split(flow, flowXY);

		&lt;span class=&quot;synComment&quot;&gt;// 極座標に変換&lt;/span&gt;
		Mat magnitude, angle;
		cartToPolar(flowXY[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;], flowXY[&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;], magnitude, angle, &lt;span class=&quot;synConstant&quot;&gt;true&lt;/span&gt;);

		&lt;span class=&quot;synComment&quot;&gt;//  色相（H）はオプティカルフローの角度&lt;/span&gt;
		&lt;span class=&quot;synComment&quot;&gt;//  彩度（S）は0～1に正規化したオプティカルフローの大きさ&lt;/span&gt;
		&lt;span class=&quot;synComment&quot;&gt;//  明度（V）は1&lt;/span&gt;
		Mat hsvPlanes[&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;];
		hsvPlanes[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;] = angle;
		hsvPlanes[&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;] = magnitude;
		hsvPlanes[&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;] = Mat::ones(angle.size(), CV_32F);
		&lt;span class=&quot;synComment&quot;&gt;//  HSVを合成して一枚の画像にする&lt;/span&gt;
		Mat hsv;
		merge(hsvPlanes, &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;, hsv);

		&lt;span class=&quot;synComment&quot;&gt;// 表示&lt;/span&gt;
		imshow(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;DeepFlow&amp;quot;&lt;/span&gt;, hsv);

		&lt;span class=&quot;synComment&quot;&gt;// 前のフレームを保存&lt;/span&gt;
		prev = curr;
	}
}
&lt;/pre&gt;&lt;p&gt;結果はこんな感じ．かなり時間かかった．&lt;br /&gt;
ちょいちょい真っ赤になるのは仕様なのかバグなのか．&lt;/p&gt;&lt;p&gt;&lt;iframe width=&quot;420&quot; height=&quot;315&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot; src=&quot;https://youtube.googleapis.com/v/pCoA0dc9gGE&amp;feature&amp;amp;source=uds&quot;&gt;&lt;/iframe&gt;&lt;br&gt;&lt;a href=&quot;http://www.youtube.com/watch?v=pCoA0dc9gGE&amp;feature&quot;&gt;OpenCVでDeepFlow - YouTube&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C++" label="C++" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <category term="Programming" label="Programming" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/e9bb4fe4fdd1dc01eff5c5a53c394c7a077a6f3f/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140821%2F20140821140023.jpg" type="image/jpeg" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>OpenCV3.0.0-alphaの特徴抽出・マッチングまとめ</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/08/20/200215"/>
        <id>hatenablog://entry/12921228815730771882</id>
        <published>2014-08-20T20:02:15+09:00</published>
        <updated>2014-08-20T20:02:15+09:00</updated>        <summary type="html">OpenCV3.0.0-alphaのパッケージが公開されたと話題になっていたので使ってみる．Change Logを見るとAKAZE特徴量が組み込まれている． AKAZE特徴量の紹介と他特徴量との比較 - 遥かへのスピードランナー によるとAKAZE特徴量は，以前のOpenCVでもakaze-opencvというパッケージを入れれば使えたが，OpenCV3.0.0-alphaでは元々組み込まれているのでそのまま使えるようだ．逆にSIFTやSURFなんかは元々OpenCVで使えたが OpenCV 3.0.0-alphaでSIFT/SURFを使う | .COM-POUND によると，opencv_co…</summary>
        <content type="html">&lt;p&gt;OpenCV3.0.0-alphaのパッケージが&lt;a href=&quot;http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0-alpha/&quot;&gt;&amp;#x516C;&amp;#x958B;&amp;#x3055;&amp;#x308C;&amp;#x305F;&lt;/a&gt;と話題になっていたので使ってみる．&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://code.opencv.org/projects/opencv/wiki/ChangeLog#30-alpha&quot;&gt;Change Log&lt;/a&gt;を見るとAKAZE特徴量が組み込まれている．&lt;br /&gt;
&lt;a href=&quot;http://poly.hatenablog.com/entry/2014/01/06/063012&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fpoly.hatenablog.com%2Fentry%2F2014%2F01%2F06%2F063012&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://poly.hatenablog.com/entry/2014/01/06/063012&quot;&gt;AKAZE&amp;#x7279;&amp;#x5FB4;&amp;#x91CF;&amp;#x306E;&amp;#x7D39;&amp;#x4ECB;&amp;#x3068;&amp;#x4ED6;&amp;#x7279;&amp;#x5FB4;&amp;#x91CF;&amp;#x3068;&amp;#x306E;&amp;#x6BD4;&amp;#x8F03; - &amp;#x9065;&amp;#x304B;&amp;#x3078;&amp;#x306E;&amp;#x30B9;&amp;#x30D4;&amp;#x30FC;&amp;#x30C9;&amp;#x30E9;&amp;#x30F3;&amp;#x30CA;&amp;#x30FC;&lt;/a&gt;&lt;br /&gt;
によるとAKAZE特徴量は，以前のOpenCVでも&lt;a href=&quot;https://github.com/thorikawa/akaze-opencv&quot;&gt;akaze-opencv&lt;/a&gt;というパッケージを入れれば使えたが，OpenCV3.0.0-alphaでは元々組み込まれているのでそのまま使えるようだ．&lt;/p&gt;&lt;p&gt;逆にSIFTやSURFなんかは元々OpenCVで使えたが&lt;br /&gt;
&lt;a href=&quot;http://www.yasutomo57jp.com/2014/08/19/opencv-3-0-0-alpha%E3%81%A7siftsurf%E3%82%92%E4%BD%BF%E3%81%86/&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.yasutomo57jp.com%2F2014%2F08%2F19%2Fopencv-3-0-0-alpha%25E3%2581%25A7siftsurf%25E3%2582%2592%25E4%25BD%25BF%25E3%2581%2586%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.yasutomo57jp.com/2014/08/19/opencv-3-0-0-alpha%E3%81%A7siftsurf%E3%82%92%E4%BD%BF%E3%81%86/&quot;&gt;OpenCV 3.0.0-alpha&amp;#x3067;SIFT/SURF&amp;#x3092;&amp;#x4F7F;&amp;#x3046; | .COM-POUND&lt;/a&gt;&lt;br /&gt;
によると，&lt;a href=&quot;https://github.com/Itseez/opencv_contrib&quot;&gt;opencv_contrib&lt;/a&gt;に移動されてしまいOpenCVと一緒にビルドしないと使えないようである．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;OpenCV3.0.0-alphaでの変更点まとめ&lt;/h3&gt;
    &lt;p&gt;以前当ブログで&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/07/135810&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2013%2F12%2F07%2F135810&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/07/135810&quot;&gt;OpenCV&amp;#x3067;&amp;#x753B;&amp;#x50CF;&amp;#x306E;&amp;#x7279;&amp;#x5FB4;&amp;#x62BD;&amp;#x51FA;&amp;#x30FB;&amp;#x30DE;&amp;#x30C3;&amp;#x30C1;&amp;#x30F3;&amp;#x30B0;&amp;#x3092;&amp;#x884C;&amp;#x3046; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
にOpenCV2.4.7の画像の特徴抽出あたりをまとめた記事を書いていたので，今回はOpenCV3.0.0-alphaでの変更点をまとめてみる．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;特徴点抽出（FeatureDetectorインターフェース）&lt;/h4&gt;
    
&lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;th&gt;FeatureDetector&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;OpenCV2.4.7&lt;/th&gt;
    &lt;td&gt;FAST，&lt;span style=&quot;color: #c0c0c0&quot;&gt;FASTX&lt;/span&gt;，&lt;span style=&quot;color: #0000ff&quot;&gt;STAR&lt;/span&gt;，&lt;span style=&quot;color: #0000ff&quot;&gt;SIFT&lt;/span&gt;，&lt;span style=&quot;color: #0000ff&quot;&gt;SURF&lt;/span&gt;，ORB，BRISK，MSER，GFTT，HARRIS，&lt;span style=&quot;color: #c0c0c0&quot;&gt;Dense&lt;/span&gt;，SimpleBlob&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;OpenCV3.0.0-alpha&lt;/th&gt;
    &lt;td&gt;FAST，ORB，BRISK，MSER，GFTT，HARRIS，SimpleBlob，&lt;span style=&quot;color: #ff0000&quot;&gt;KAZE&lt;/span&gt;，&lt;span style=&quot;color: #ff0000&quot;&gt;AKAZE&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;opencv_contrib&lt;/th&gt;
    &lt;td&gt;STAR，SIFT，SURF&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;赤字&lt;/span&gt;はOpenCV3.0.0-alphaで追加されたもの．&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;青字&lt;/span&gt;はopencv_contribを入れれば使えるもの．&lt;br /&gt;
&lt;span style=&quot;color: #c0c0c0&quot;&gt;灰色&lt;/span&gt;はOpenCV3.0.0-alphaでなくなってしまってopencv_contribにも入ってないもの．&lt;/p&gt;&lt;p&gt;FASTXとDenseはなくなってしまったようである．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;特徴記述（DescriptorExtractorインターフェース）&lt;/h4&gt;
    
&lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;th&gt;DescriptorExtractor&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;OpenCV2.4.7&lt;/th&gt;
    &lt;td&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;SIFT&lt;/span&gt;，&lt;span style=&quot;color: #0000ff&quot;&gt;SURF&lt;/span&gt;，&lt;span style=&quot;color: #0000ff&quot;&gt;BRIEF&lt;/span&gt;，BRISK，ORB，&lt;span style=&quot;color: #0000ff&quot;&gt;FRIEK&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;OpenCV3.0.0-alpha&lt;/th&gt;
    &lt;td&gt;BRISK，ORB，&lt;span style=&quot;color: #ff0000&quot;&gt;KAZE&lt;/span&gt;，&lt;span style=&quot;color: #ff0000&quot;&gt;AKAZE&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;th&gt;opencv_contrib&lt;/th&gt;
    &lt;td&gt;SIFT，SURF，BRIEF，FREAK&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;赤字&lt;/span&gt;はOpenCV3.0.0-alphaで追加されたもの．&lt;br /&gt;
&lt;span style=&quot;color: #0000ff&quot;&gt;青字&lt;/span&gt;はopencv_contribを入れれば使えるもの．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h4&gt;特徴点マッチング（DescriptorMatcherインターフェース）&lt;/h4&gt;
    
&lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;th&gt;DescriptorExtractor&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td&gt;OpenCV2.4.7およびOpenCV3.0.0-alpha&lt;/td&gt;
    &lt;td&gt;BruteForce，BruteForce-L1，BruteForce-SL2，BruteForce-Hamming，BruteForce-Hamming(2)，FlannBased&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;DescriptorMatcherに関しては変わりがないようである．&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;AKAZEを使ってみる&lt;/h3&gt;
    &lt;p&gt;AKAZEを使ってみたかったので，OpenCV3.0.0-alphaで特徴抽出を行ってみる．ついでに他のアルゴリズムとも画像を比較してみる．特徴抽出のソースコードは以下．&lt;/p&gt;
&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;cv::String detectorNames[] = {&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;AKAZE&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;KAZE&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;FAST&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;ORB&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;BRISK&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;MSER&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;GFTT&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;HARRIS&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;SimpleBlob&amp;quot;&lt;/span&gt;,};
&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; img = cv::imread(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Penguins.jpg&amp;quot;&lt;/span&gt;);

&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;9&lt;/span&gt;; i++)
{
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; detector = cv::FeatureDetector::create(detectorNames[i]);
	std::vector&amp;lt;cv::KeyPoint&amp;gt; keyPoints;
	detector-&amp;gt;detect(img, keyPoints); 

	cv::Mat output;
	cv::drawKeypoints(img, keyPoints, output, cv::Scalar::all(-&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

	cv::imwrite(detectorNames[i] + &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;.bmp&amp;quot;&lt;/span&gt;, output);
}
&lt;/pre&gt;&lt;p&gt;&lt;hr&gt;&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;AKAZE&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194415.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194415j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194415j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;KAZE&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194424.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194424j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194424j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;FAST&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194432.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194432j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194432j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;ORB&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194437.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194437j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194437j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;BRISK&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194444.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194444j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194444j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;MSER&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194454.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194454j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194454j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;GFTT&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194459.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194459j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194459j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;HARRIS&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194510.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194510j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194510j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;SimpleBlog&lt;/h5&gt;
    &lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140820/20140820194515.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140820194515j:plain&quot; title=&quot;f:id:whoopsidaisies:20140820194515j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;</content>        
        <category term="C++" label="C++" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="OpenCV 3.0" label="OpenCV 3.0" />
        
        <category term="Programming" label="Programming" />
        
        <category term="コンピュータビジョン" label="コンピュータビジョン" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/55cb74f4e90b41a529bbd05f97efcc0105dd006c/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140820%2F20140820194415.jpg" type="image/jpeg" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#でDeep Learning（Accord.NETによる方法）</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/08/19/015420"/>
        <id>hatenablog://entry/12921228815730581582</id>
        <published>2014-08-19T01:54:20+09:00</published>
        <updated>2014-08-19T01:54:20+09:00</updated>        <summary type="html">流行りのDeep LearningをC#で試してみる．機械学習やコンピュータビジョン，信号処理等の.NET向けのオープンソースのライブラリであるAccord.NET FrameworkにDeep Learningが実装されているのでそれを使う．Deep Belief Networks(DBN), Deep Neural Networks(DNNs)とおまけにRestricted Boltzmann Machine(RBM)を単体で動かしてみる．Deep Learning自体については以下のページ等を参考に． MIRU2014 tutorial deeplearning Deep Learnin…</summary>
        <content type="html">&lt;p&gt;流行りのDeep LearningをC#で試してみる．機械学習やコンピュータビジョン，信号処理等の.NET向けのオープンソースのライブラリである&lt;a href=&quot;http://accord-framework.net/&quot;&gt;Accord.NET Framework&lt;/a&gt;にDeep Learningが実装されているのでそれを使う．&lt;/p&gt;&lt;p&gt;Deep Belief Networks(DBN), Deep Neural Networks(DNNs)とおまけにRestricted Boltzmann Machine(RBM)を単体で動かしてみる．&lt;/p&gt;&lt;p&gt;Deep Learning自体については以下のページ等を参考に．&lt;br /&gt;
&lt;a href=&quot;http://www.slideshare.net/Takayosi/miru2014-tutorial-deeplearning-37219713&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.slideshare.net%2FTakayosi%2Fmiru2014-tutorial-deeplearning-37219713&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.slideshare.net/Takayosi/miru2014-tutorial-deeplearning-37219713&quot;&gt;MIRU2014 tutorial deeplearning&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.slideshare.net/beam2d/deep-learning20140130&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.slideshare.net%2Fbeam2d%2Fdeep-learning20140130&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.slideshare.net/beam2d/deep-learning20140130&quot;&gt;Deep Learning&amp;#x6280;&amp;#x8853;&amp;#x306E;&amp;#x4ECA;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.vision.is.tohoku.ac.jp/files/9313/6601/7876/CVIM_tutorial_deep_learning.pdf&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwww.vision.is.tohoku.ac.jp%2Ffiles%2F9313%2F6601%2F7876%2FCVIM_tutorial_deep_learning.pdf&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.vision.is.tohoku.ac.jp/files/9313/6601/7876/CVIM_tutorial_deep_learning.pdf&quot;&gt;&amp;#x30C7;&amp;#x30A3;&amp;#x30FC;&amp;#x30D7;&amp;#x30E9;&amp;#x30FC;&amp;#x30CB;&amp;#x30F3;&amp;#x30B0; &amp;#x30C1;&amp;#x30E5;&amp;#x30FC;&amp;#x30C8;&amp;#x30EA;&amp;#x30A2;&amp;#x30EB;&amp;#xFF08;&amp;#x3082;&amp;#x3057;&amp;#x304F;&amp;#x306F;&amp;#x7814;&amp;#x7A76;&amp;#x52D5;&amp;#x5411;&amp;#x5831;&amp;#x544A;&amp;#xFF09;&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Accord.NETのインストール&lt;/h3&gt;
    &lt;p&gt;NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「Accord.Neuro」を検索・インストール．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140819/20140819013518.png&quot; alt=&quot;f:id:whoopsidaisies:20140819013518p:plain&quot; title=&quot;f:id:whoopsidaisies:20140819013518p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#dbn1&quot;&gt;Deep Belief Networks(DBN) - 教師あり学習(Back propagation)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#dbn2&quot;&gt;Deep Belief Networks(DBN) - 教師なし学習(Contrastive Divergence)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#dnn&quot;&gt;Deep Neural Networks(DNNs)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#rbm&quot;&gt;Restricted Boltzmann Machine(RBM)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;を動かすサンプルコードを載せていくが，いずれのサンプルでも以下のusingを書いておくこと．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; Accord.Neuro;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; Accord.Neuro.Networks;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; Accord.Neuro.Learning;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; AForge.Neuro.Learning;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; Accord.Neuro.ActivationFunctions;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; Accord.Math;
&lt;/pre&gt;&lt;p&gt;&lt;a name = &quot;dbn1&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Deep Belief Networks(DBN) - 教師あり学習(Back propagation)&lt;/h3&gt;
    &lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// トレーニングデータ&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] inputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
};
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] outputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
};

&lt;span class=&quot;synComment&quot;&gt;// DBNの生成&lt;/span&gt;
var network = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; DeepBeliefNetwork(
&lt;span class=&quot;synStatement&quot;&gt;    inputsCount:&lt;/span&gt; inputs.Length,         &lt;span class=&quot;synComment&quot;&gt;// 入力層の次元&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;    hiddenNeurons:&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; }); &lt;span class=&quot;synComment&quot;&gt;// 隠れ層と出力層の次元&lt;/span&gt;

&lt;span class=&quot;synComment&quot;&gt;// ネットワークの重みをガウス分布で初期化する&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; GaussianWeights(network).Randomize();
network.UpdateVisibleWeights();

&lt;span class=&quot;synComment&quot;&gt;// DBNの学習アルゴリズムの生成  5000回繰り返し入力&lt;/span&gt;
var teacher = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; BackPropagationLearning(network);                        
&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;5000&lt;/span&gt;; i++)
    teacher.RunEpoch(inputs, outputs);

&lt;span class=&quot;synComment&quot;&gt;// 重みの更新&lt;/span&gt;
network.UpdateVisibleWeights();

&lt;span class=&quot;synComment&quot;&gt;// 学習されたネットワークでテストデータが各クラスに属する確率を計算&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] input = { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; };
var output = network.Compute(input);

&lt;span class=&quot;synComment&quot;&gt;//  一番確率の高いクラスのインデックスを得る&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; imax; output.Max(&lt;span class=&quot;synStatement&quot;&gt;out&lt;/span&gt; imax);

&lt;span class=&quot;synComment&quot;&gt;// 結果出力&lt;/span&gt;
Console.WriteLine(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;class : {0}&amp;quot;&lt;/span&gt;, imax);
&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (var o &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; output)
{
    Console.Write(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;{0} &amp;quot;&lt;/span&gt;, o);
}
&lt;/pre&gt;&lt;p&gt;実行結果&lt;/p&gt;
&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;class : 0
0.883118949465337 0.115560850111682&lt;/pre&gt;&lt;p&gt;&lt;a name=&quot;#dbn2&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Deep Belief Networks(DBN) - 教師なし学習(Contrastive Divergence)&lt;/h3&gt;
    &lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// トレーニングデータ&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] inputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
};

&lt;span class=&quot;synComment&quot;&gt;// DBNの生成&lt;/span&gt;
var network = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; DeepBeliefNetwork(
&lt;span class=&quot;synStatement&quot;&gt;    inputsCount:&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;6&lt;/span&gt;,
&lt;span class=&quot;synStatement&quot;&gt;    hiddenNeurons:&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; });

&lt;span class=&quot;synComment&quot;&gt;// ネットワークの重みをガウス分布で初期化する&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; GaussianWeights(network).Randomize();
network.UpdateVisibleWeights();

&lt;span class=&quot;synComment&quot;&gt;// DBNの学習アルゴリズムの生成  5000回繰り返し入力&lt;/span&gt;
var teacher = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; DeepBeliefNetworkLearning(network)
{
    Algorithm = (h, v, i) =&amp;gt; &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ContrastiveDivergenceLearning(h, v)
};
var layerData = teacher.GetLayerInput(inputs);
&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;5000&lt;/span&gt;; i++)
    teacher.RunEpoch(layerData);
&lt;span class=&quot;synComment&quot;&gt;// 重みの更新&lt;/span&gt;
network.UpdateVisibleWeights();

&lt;span class=&quot;synComment&quot;&gt;// 学習されたネットワークでテストデータが各クラスに属する確率を計算&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] input = { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; };
var output = network.Compute(input);

&lt;span class=&quot;synComment&quot;&gt;//  一番確率の高いクラスのインデックスを得る&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; imax; output.Max(&lt;span class=&quot;synStatement&quot;&gt;out&lt;/span&gt; imax);

&lt;span class=&quot;synComment&quot;&gt;// 結果出力&lt;/span&gt;
Console.WriteLine(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;class : {0}&amp;quot;&lt;/span&gt;, imax);
&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (var o &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; output)
{
    Console.Write(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;{0} &amp;quot;&lt;/span&gt;, o);
}
&lt;/pre&gt;&lt;p&gt;実行結果&lt;/p&gt;
&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;class : 1
0.529437183967883 0.554114047128916&lt;/pre&gt;&lt;p&gt;&lt;a name=&quot;#dnn&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Deep Neural Networks(DNNs)&lt;/h3&gt;
    &lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// トレーニングデータ&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] inputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
};
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] outputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
};

&lt;span class=&quot;synComment&quot;&gt;// ネットワークの生成&lt;/span&gt;
var network = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; DeepBeliefNetwork(
&lt;span class=&quot;synStatement&quot;&gt;    inputsCount:&lt;/span&gt; inputs.Length,         &lt;span class=&quot;synComment&quot;&gt;// 入力層の次元&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;    hiddenNeurons:&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; }); &lt;span class=&quot;synComment&quot;&gt;// 隠れ層と出力層の次元&lt;/span&gt;

&lt;span class=&quot;synComment&quot;&gt;// DNNの学習アルゴリズムの生成&lt;/span&gt;
var teacher = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; DeepNeuralNetworkLearning(network)
{
    Algorithm = (ann, i) =&amp;gt; &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ParallelResilientBackpropagationLearning(ann),
    LayerIndex = network.Machines.Count - &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;,
};

&lt;span class=&quot;synComment&quot;&gt;// 5000回繰り返し学習&lt;/span&gt;
var layerData = teacher.GetLayerInput(inputs);
&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;5000&lt;/span&gt;; i++)
    teacher.RunEpoch(layerData, outputs);

&lt;span class=&quot;synComment&quot;&gt;// 重みの更新&lt;/span&gt;
network.UpdateVisibleWeights();

&lt;span class=&quot;synComment&quot;&gt;// 学習されたネットワークでテストデータが各クラスに属する確率を計算&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] input = { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; };
var output = network.Compute(input);

&lt;span class=&quot;synComment&quot;&gt;//  一番確率の高いクラスのインデックスを得る&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; imax; output.Max(&lt;span class=&quot;synStatement&quot;&gt;out&lt;/span&gt; imax);

&lt;span class=&quot;synComment&quot;&gt;// 結果出力&lt;/span&gt;
Console.WriteLine(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;class : {0}&amp;quot;&lt;/span&gt;, imax);
&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (var o &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; output)
{
    Console.Write(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;{0} &amp;quot;&lt;/span&gt;, o);
}
&lt;/pre&gt;&lt;p&gt;実行結果&lt;/p&gt;
&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;class : 0
0.999680477117216 0.00120961077917418&lt;/pre&gt;&lt;p&gt;&lt;a name=&quot;#rbm&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Restricted Boltzmann Machine(RBM)&lt;/h3&gt;
    &lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// トレーニングデータ&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] inputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
};
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[][] outputs = {
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] { &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; },
};

&lt;span class=&quot;synComment&quot;&gt;// RBMの生成&lt;/span&gt;
var rbm = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; RestrictedBoltzmannMachine(
&lt;span class=&quot;synStatement&quot;&gt;    inputsCount:&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;6&lt;/span&gt;, 
&lt;span class=&quot;synStatement&quot;&gt;    hiddenNeurons:&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;);

&lt;span class=&quot;synComment&quot;&gt;// トレーニングデータで学習&lt;/span&gt;
var teacher = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ContrastiveDivergenceLearning(rbm);
&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;5000&lt;/span&gt;; i++)
    teacher.RunEpoch(inputs);

&lt;span class=&quot;synComment&quot;&gt;// テストデータ&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;[] input = { &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; };

&lt;span class=&quot;synComment&quot;&gt;// 学習されたネットワークで各クラスに属する確率を計算&lt;/span&gt;
var output = rbm.Compute(input);

&lt;span class=&quot;synComment&quot;&gt;//  一番確率の高いクラスのインデックスを得る&lt;/span&gt;
&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; imax; output.Max(&lt;span class=&quot;synStatement&quot;&gt;out&lt;/span&gt; imax);

&lt;span class=&quot;synComment&quot;&gt;// 結果出力&lt;/span&gt;
Console.WriteLine(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;class : {0}&amp;quot;&lt;/span&gt;, imax);
&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (var o &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; output)
{
    Console.Write(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;{0} &amp;quot;&lt;/span&gt;, o);
}
&lt;/pre&gt;&lt;p&gt;実行結果&lt;/p&gt;
&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;class : 1
0.133832413712274 0.906343089146992&lt;/pre&gt;
&lt;/div&gt;</content>        
        <category term=".NET" label=".NET" />
        
        <category term="Accord.NET" label="Accord.NET" />
        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term="機械学習" label="機械学習" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/bf55f3040436323088987256a75370783ee591d6/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140819%2F20140819013518.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#でSVM　libsvm.netによる方法</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/08/16/183002"/>
        <id>hatenablog://entry/12921228815730367189</id>
        <published>2014-08-16T18:30:02+09:00</published>
        <updated>2014-08-16T18:30:02+09:00</updated>        <summary type="html">SVMのライブラリであるLIBSVMを.NETプロジェクトで使えるようにするlibsvm.netを動かしてみる． libsvm.netのインストール NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「libsvm.net」を検索・インストール． 動作確認 libsvm.netでは，トレーニングデータやテストデータをLIBSVMと同じ形式でファイルから入力できる．データのフォーマットは以下の通りである． &amp;ltlabel&gt; &amp;ltindex1&gt;:&amp;ltvalue1&gt; &amp;ltindex2&gt;:&amp;ltvalue2&gt; ... &amp;lti…</summary>
        <content type="html">&lt;p&gt;SVMのライブラリである&lt;a href=&quot;http://www.csie.ntu.edu.tw/~cjlin/libsvm/&quot;&gt;LIBSVM&lt;/a&gt;を.NETプロジェクトで使えるようにする&lt;a href=&quot;https://code.google.com/p/libsvm-net/&quot;&gt;libsvm.net&lt;/a&gt;を動かしてみる．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;libsvm.netのインストール&lt;/h3&gt;
    &lt;p&gt;NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「libsvm.net」を検索・インストール．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;動作確認&lt;/h3&gt;
    &lt;p&gt;libsvm.netでは，トレーニングデータやテストデータをLIBSVMと同じ形式でファイルから入力できる．データのフォーマットは以下の通りである．&lt;/p&gt;

    &lt;blockquote cite=&quot;http://bio-info.biz/tips/libsvm_data_format.html&quot;&gt;
        &lt;p&gt;&amp;ltlabel&amp;gt &amp;ltindex1&amp;gt:&amp;ltvalue1&amp;gt &amp;ltindex2&amp;gt:&amp;ltvalue2&amp;gt ... &amp;ltindexN&amp;gt:&amp;ltvalueN&amp;gt&lt;br /&gt;
&amp;ltlabel&amp;gt &amp;ltindex1&amp;gt:&amp;ltvalue1&amp;gt &amp;ltindex2&amp;gt:&amp;ltvalue2&amp;gt ... &amp;ltindexN&amp;gt:&amp;ltvalueN&amp;gt&lt;br /&gt;
&amp;ltlabel&amp;gt &amp;ltindex1&amp;gt:&amp;ltvalue1&amp;gt &amp;ltindex2&amp;gt:&amp;ltvalue2&amp;gt ... &amp;ltindexN&amp;gt:&amp;ltvalueN&amp;gt&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&amp;ltlabel&amp;gt &amp;ltindex1&amp;gt:&amp;ltvalue1&amp;gt &amp;ltindex2&amp;gt:&amp;ltvalue2&amp;gt ... &amp;ltindexN&amp;gt:&amp;ltvalueN&amp;gt&lt;/p&gt;

        &lt;cite&gt;&lt;a href=&quot;http://bio-info.biz/tips/libsvm_data_format.html&quot;&gt;LIBSVM&amp;#x306E;&amp;#x5165;&amp;#x529B;&amp;#x30C7;&amp;#x30FC;&amp;#x30BF;&amp;#x5F62;&amp;#x5F0F;&amp;#x306B;&amp;#x3064;&amp;#x3044;&amp;#x3066;&lt;/a&gt;&lt;/cite&gt;
    &lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&quot;http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/&quot;&gt;&amp;#x3053;&amp;#x3053;&lt;/a&gt;にLIBSVM用のデータセットが落ちていたので，&lt;a href=&quot;http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#fourclass&quot;&gt;fourclass&lt;/a&gt;というデータセットを使ってみる．&lt;/p&gt;&lt;p&gt;以下に，分類器を動かすソースコード乗せる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// トレーニングデータの読み込み&lt;/span&gt;
var training = libsvm.ProblemHelper.ReadProblem(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;fourclass&amp;quot;&lt;/span&gt;);
&lt;span class=&quot;synComment&quot;&gt;// RBFカーネルを生成&lt;/span&gt;
var gamma = &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;;
var kernel = libsvm.KernelHelper.RadialBasisFunctionKernel(gamma);
&lt;span class=&quot;synComment&quot;&gt;// C-SVC用のクラスの生成&lt;/span&gt;
var c = &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;;
var svm = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; libsvm.C_SVC(training, kernel, c);

&lt;span class=&quot;synComment&quot;&gt;// テストデータの読み込み（面倒だったのでトレーニングデータをそのまま使ってる）&lt;/span&gt;
var test = libsvm.ProblemHelper.ReadProblem(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;fourclass&amp;quot;&lt;/span&gt;);
&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; test.l; i++)
{
    &lt;span class=&quot;synComment&quot;&gt;// 予測値&lt;/span&gt;
    var z = svm.Predict(test.x[i]);
    &lt;span class=&quot;synComment&quot;&gt;// 入力ファイルについているラベル&lt;/span&gt;
    var y = test.y[i];
    &lt;span class=&quot;synComment&quot;&gt;// 予測値と正解値を出力&lt;/span&gt;
    Console.WriteLine(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;{0}:{1} {2}&amp;quot;&lt;/span&gt;, i, z, y);
}
&lt;/pre&gt;&lt;p&gt;トレーニングデータとテストデータは同じものを使った．実行すると，予測値と正解値が出力される．&lt;/p&gt;&lt;p&gt;上記コードではパラメータ選択とかまでは行っていないが，結構簡単に使えそう．他にも回帰 (ϵ-SVR)や外れ値検出 (One-Class SVM) が出来るようである．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term=".NET" label=".NET" />
        
        <category term="C#" label="C#" />
        
        <category term="機械学習" label="機械学習" />
        
        <category term="NuGet" label="NuGet" />
        
        <category term="Programming" label="Programming" />
        
        <link rel="enclosure" href="https://ogimage.blog.st-hatena.com/6435988827676239766/12921228815730367189/1410220281" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C# LINQでFIRフィルタ</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/07/18/233242"/>
        <id>hatenablog://entry/12921228815728446895</id>
        <published>2014-07-18T23:32:42+09:00</published>
        <updated>2014-07-18T23:32:42+09:00</updated>        <summary type="html">LINQを使った，FIRフィルタ演算を行う関数． ソースコード /// &lt;summary&gt; /// FIRフィルタをかけたデータを返す /// &lt;/summary&gt; /// &lt;param name=&quot;data&quot;&gt;入力データ&lt;/param&gt; /// &lt;param name=&quot;coefficients&quot;&gt;フィルタ係数&lt;/param&gt; /// &lt;returns&gt;FIRフィルタをかけたデータ&lt;/returns&gt; List&lt;double&gt; FiniteImpulseResponseFilter( List&lt;double&gt; data, List&lt;double&gt; coefficients) { return…</summary>
        <content type="html">&lt;p&gt;LINQを使った，FIRフィルタ演算を行う関数．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// FIRフィルタをかけたデータを返す&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;入力データ&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;coefficients&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;フィルタ係数&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;FIRフィルタをかけたデータ&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
List&amp;lt;&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;&amp;gt; FiniteImpulseResponseFilter(
    List&amp;lt;&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;&amp;gt; data,
    List&amp;lt;&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;&amp;gt; coefficients)
{
    &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; Enumerable.Range(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, data.Count - coefficients.Count)
        .Select(i =&amp;gt; data.Skip(i).Take(coefficients.Count)
            .Zip(coefficients, (d, c) =&amp;gt; d * c).Sum())
        .ToList();
}
&lt;/pre&gt;&lt;p&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/07/18/225436&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2014%2F07%2F18%2F225436&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/07/18/225436&quot;&gt;C# LINQ&amp;#x3067;&amp;#x79FB;&amp;#x52D5;&amp;#x5E73;&amp;#x5747; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
をベースにした．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;.Zip(coefficients, (d, c) =&amp;gt; d * c).Sum()
&lt;/pre&gt;&lt;p&gt;の部分で入力データとフィルタ係数の積和演算を行っている．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="LINQ" label="LINQ" />
        
        <category term="ディジタル信号処理" label="ディジタル信号処理" />
        
        <link rel="enclosure" href="https://ogimage.blog.st-hatena.com/6435988827676239766/12921228815728446895/1410220263" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
    <entry>
        <title>C# LINQで移動平均</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/07/18/225436"/>
        <id>hatenablog://entry/12921228815728442770</id>
        <published>2014-07-18T22:54:36+09:00</published>
        <updated>2014-07-18T22:54:36+09:00</updated>        <summary type="html">LINQを使った，移動平均を計算する関数． ソースコード /// &lt;summary&gt; /// 移動平均を格納した配列を返す /// &lt;/summary&gt; /// &lt;param name=&quot;data&quot;&gt;入力データ&lt;/param&gt; /// &lt;param name=&quot;num&quot;&gt;何個分の平均をとるか&lt;/param&gt; /// &lt;returns&gt;移動平均をとったデータ&lt;/returns&gt; List&lt;double&gt; MovingAverage( List&lt;double&gt; data, int num) { return Enumerable.Range(0, data.Count - num) .Select…</summary>
        <content type="html">&lt;p&gt;LINQを使った，移動平均を計算する関数．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// 移動平均を格納した配列を返す&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;入力データ&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;num&amp;quot;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;何個分の平均をとるか&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;param&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;/// &lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;synComment&quot;&gt;移動平均をとったデータ&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
List&amp;lt;&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;&amp;gt; MovingAverage(
    List&amp;lt;&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt;&amp;gt; data,
    &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; num)
{
    &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; Enumerable.Range(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, data.Count - num)
        .Select(i =&amp;gt; data.Skip(i).Take(num).Average())
        .ToList();
}
&lt;/pre&gt;&lt;p&gt;LINQの練習用なので効率が良いかとかは知らない．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;Enumerable.Range(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;, data.Count - num)
&lt;/pre&gt;&lt;p&gt;で，0～総データ数－平均を求めるときのデータの個数までの整数のシーケンスを生成する．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;data.Skip(i).Take(num).Average()
&lt;/pre&gt;&lt;p&gt;で，入力データのi番目のデータからnum個データを抽出して平均をとる．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;その他&lt;/h3&gt;
    &lt;p&gt;FIRフィルタは以下の記事．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/07/18/233242&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2014%2F07%2F18%2F233242&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/07/18/233242&quot;&gt;C# LINQ&amp;#x3067;FIR&amp;#x30D5;&amp;#x30A3;&amp;#x30EB;&amp;#x30BF; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="ディジタル信号処理" label="ディジタル信号処理" />
        
        <category term="LINQ" label="LINQ" />
        
        <link rel="enclosure" href="https://ogimage.blog.st-hatena.com/6435988827676239766/12921228815728442770/1410220225" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#でExcelファイルを作成・グラフを挿入する　NetOfficeによる方法</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/06/19/101032"/>
        <id>hatenablog://entry/12921228815726400684</id>
        <published>2014-06-19T10:10:32+09:00</published>
        <updated>2014-06-19T10:10:32+09:00</updated>        <summary type="html">C#からExcelファイルを作って，グラフも挿入したい．以前，以下の記事でClosedXmlというライブラリを使ってC#から簡単にExcelファイルを作る方法を紹介したが，グラフの挿入が出来ないのがグラフの挿入が出来ないのが気になっていた． C#でExcelファイルを作成する ClosedXmlを使用 - whoopsidaisies&#39;s diaryNetOfficeというライブラリを使えば，ClosedXmlと同じくらい簡単にExcelファイルが作成でき，さらにグラフの挿入も行えるので，今回はその方法を紹介する． NetOfficeのインストール NetOfficeはMicrosoft Of…</summary>
        <content type="html">&lt;p&gt;C#からExcelファイルを作って，グラフも挿入したい．&lt;/p&gt;&lt;p&gt;以前，以下の記事で&lt;a href=&quot;https://closedxml.codeplex.com/&quot;&gt;ClosedXml&lt;/a&gt;というライブラリを使ってC#から簡単にExcelファイルを作る方法を紹介したが，グラフの挿入が出来ないのがグラフの挿入が出来ないのが気になっていた．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/11/12/092843&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2013%2F11%2F12%2F092843&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/11/12/092843&quot;&gt;C#&amp;#x3067;Excel&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x3092;&amp;#x4F5C;&amp;#x6210;&amp;#x3059;&amp;#x308B; ClosedXml&amp;#x3092;&amp;#x4F7F;&amp;#x7528; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://netoffice.codeplex.com/&quot;&gt;NetOffice&lt;/a&gt;というライブラリを使えば，ClosedXmlと同じくらい簡単にExcelファイルが作成でき，さらにグラフの挿入も行えるので，今回はその方法を紹介する．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;NetOfficeのインストール&lt;/h3&gt;
    &lt;p&gt;&lt;a href=&quot;http://netoffice.codeplex.com/&quot;&gt;NetOffice&lt;/a&gt;はMicrosoft Officeにアクセスするための.NETのライブラリで，今回紹介するExcel以外にも，Word, PowerPoint等にもアクセスできるらしい．&lt;/p&gt;&lt;p&gt;インストールはNuget経由で可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから検索て「NetOffice.Excel」をインストールする．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140619/20140619095605.png&quot; alt=&quot;f:id:whoopsidaisies:20140619095605p:plain&quot; title=&quot;f:id:whoopsidaisies:20140619095605p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;動作確認&lt;/h3&gt;
    &lt;p&gt;以下，動作確認用のソースコードと生成されたExcelファイルの中身．実行環境ではExcel2010がインストール済み．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synType&quot;&gt;class&lt;/span&gt; Program
{
    &lt;span class=&quot;synType&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; Main(&lt;span class=&quot;synType&quot;&gt;string&lt;/span&gt;[] args)
    {
        &lt;span class=&quot;synComment&quot;&gt;// Excelを開く&lt;/span&gt;
        &lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var excelApplication = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; NetOffice.ExcelApi.Application())
        {
            &lt;span class=&quot;synComment&quot;&gt;// ワークブックを追加&lt;/span&gt;
            var workBook = excelApplication.Workbooks.Add();
            &lt;span class=&quot;synComment&quot;&gt;// ワークシートを取得&lt;/span&gt;
            var workSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;];

            &lt;span class=&quot;synComment&quot;&gt;// データの入力&lt;/span&gt;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;ブラウザシェア&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;IE&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;52.56%&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Chrome&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;24.7%&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Firefox&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;12.92%&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;その他&amp;quot;&lt;/span&gt;;
            workSheet.Cells[&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;].Value = &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;=1-B2-B3-B4&amp;quot;&lt;/span&gt;;
                
            &lt;span class=&quot;synComment&quot;&gt;// グラフオブジェクトの追加&lt;/span&gt;
            var chart = ((NetOffice.ExcelApi.ChartObjects)workSheet.ChartObjects()).Add(&lt;span class=&quot;synConstant&quot;&gt;70&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;375&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;225&lt;/span&gt;);
            &lt;span class=&quot;synComment&quot;&gt;// 円グラフに設定&lt;/span&gt;
            chart.Chart.ChartType = NetOffice.ExcelApi.Enums.XlChartType.xlPie;
            &lt;span class=&quot;synComment&quot;&gt;// データ範囲を指定&lt;/span&gt;
            chart.Chart.SetSourceData(workSheet.Range(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;A1:B5&amp;quot;&lt;/span&gt;));

            &lt;span class=&quot;synComment&quot;&gt;// 保存（環境に合わせて拡張子xlsとかでも大丈夫みたい）&lt;/span&gt;
            workBook.SaveAs(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;d:\test.xlsx&amp;quot;&lt;/span&gt;);

            &lt;span class=&quot;synComment&quot;&gt;// Excelを終了する&lt;/span&gt;
            excelApplication.Quit();
        }
    }
}
&lt;/pre&gt;&lt;p&gt;出来上がったExcelファイルの中身はこんな感じ．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140619/20140619094620.png&quot; alt=&quot;f:id:whoopsidaisies:20140619094620p:plain&quot; title=&quot;f:id:whoopsidaisies:20140619094620p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;その他&lt;/h3&gt;
    &lt;p&gt;以下のページにグラフ以外のサンプルも多数ある．&lt;br /&gt;
&lt;a href=&quot;http://netoffice.codeplex.com/wikipage?title=Excel_Examples_EN&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fnetoffice.codeplex.com%2Fwikipage%3Ftitle%3DExcel_Examples_EN&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://netoffice.codeplex.com/wikipage?title=Excel_Examples_EN&quot;&gt;NetOffice - MS Office in .NET - Home&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://pro.art55.jp/?eid=1304102&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fpro.art55.jp%2F%3Feid%3D1304102&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://pro.art55.jp/?eid=1304102&quot;&gt;&amp;#x3010;NetOffice&amp;#x3011;&amp;#x3010;Excel&amp;#x3011;NetOffice&amp;#x306E;&amp;#x307E;&amp;#x3068;&amp;#x3081; | &amp;#x5275;&amp;#x9020;&amp;#x7684;&amp;#x30D7;&amp;#x30ED;&amp;#x30B0;&amp;#x30E9;&amp;#x30DF;&amp;#x30F3;&amp;#x30B0;&amp;#x3068;&amp;#x7C98;&amp;#x571F;&amp;#x7D30;&amp;#x5DE5;&lt;/a&gt;（こっちは日本語）&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term="NuGet" label="NuGet" />
        
        <category term="Excel" label="Excel" />
        
        <category term=".NET" label=".NET" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/63f46c20bd4812deed48a936d07e7c31d4301310/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140619%2F20140619094620.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#でグラフを描く OxyPlotのFunctionSeriesによる方法</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/02/10/122939"/>
        <id>hatenablog://entry/12921228815718131111</id>
        <published>2014-02-10T12:29:39+09:00</published>
        <updated>2014-02-10T12:29:39+09:00</updated>        <summary type="html">.NETフレームワーク用のグラフ描画ライブラリであるOxyPlotを使ってグラフを描く． その中でもFunctionSeriesクラスを使って与えられた関数のグラフを描く方法を記す．OxyPlotはWindows Formアプリケーションだけでなく，WPF，Silverlight，Windows8等様々な環境で使える． Chartコントロールとの比較 Chartコントロールによるグラフの描画方法は以下の別の記事で紹介したことがあるが，比較してOxyPlotの方が良いなと思っている点をあげる． 関数を渡してこの範囲を表示するとかが楽（今回の記事のメイン．詳細は後述．たとえば のの範囲のグラフを描…</summary>
        <content type="html">&lt;p&gt;.NETフレームワーク用のグラフ描画ライブラリである&lt;a href=&quot;http://oxyplot.codeplex.com/&quot;&gt;OxyPlot&lt;/a&gt;を使ってグラフを描く．&lt;br /&gt;
その中でもFunctionSeriesクラスを使って与えられた関数のグラフを描く方法を記す．&lt;/p&gt;&lt;p&gt;OxyPlotはWindows Formアプリケーションだけでなく，WPF，Silverlight，Windows8等様々な環境で使える．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Chartコントロールとの比較&lt;/h3&gt;
    &lt;p&gt;Chartコントロールによるグラフの描画方法は以下の&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/11/26/030331&quot;&gt;&amp;#x5225;&amp;#x306E;&amp;#x8A18;&amp;#x4E8B;&lt;/a&gt;で紹介したことがあるが，比較してOxyPlotの方が良いなと思っている点をあげる．&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;関数を渡してこの範囲を表示するとかが楽（今回の記事のメイン．詳細は後述．たとえば&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;http://chart.apis.google.com/chart?cht=tx&amp;chl=y%3Dx%5E3%2B2x%5E2-3&quot; alt=&quot;y=x^3+2x^2-3&quot;/&gt;の&lt;img src=&quot;http://chart.apis.google.com/chart?cht=tx&amp;chl=-2%5Cle%20x%5Cle%202&quot; alt=&quot;-2\le x\le 2&quot;/&gt;の範囲のグラフを描画とか）&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;マウス操作によるグラフの拡大・縮小，移動等の機能が最初からついている&lt;/li&gt;
&lt;li&gt;ベクター画像できれいにグラフを保存できる（ChartコントロールでもEMFで保存できるがグラフの種類によっては汚い）&lt;/li&gt;
&lt;li&gt;配列データ等にバインディングさせて，複数のグラフを描画するとき便利な気がする（今度記事にまとめようと思います）&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;OxyPlotのインストール&lt;/h3&gt;
    &lt;p&gt;NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「OxyPlot」を検索．自分に合った環境のパッケージをインストール．（この記事ではOxyPlot.WindowsFormsを使った）&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140210/20140210110630.png&quot; alt=&quot;f:id:whoopsidaisies:20140210110630p:plain&quot; title=&quot;f:id:whoopsidaisies:20140210110630p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Plotコントロールの追加&lt;/h3&gt;
    &lt;p&gt;グラフ描画用のPlotというコントロールが用意されているので使う．&lt;/p&gt;&lt;p&gt;ツールボックスの適当なところで右クリックして「アイテムの選択(I)...」を選択．「.NET Framework コンポーネント」タブの「参照(B)...」ボタンを押して，「(ソリューションフォルダ)\packages\OxyPlot.WindowsForms.yyyy.x.xxx.x\lib\NET45\OxyPlot.WindowsForms.dll」を選択したらOK．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;a href=&quot;http://f.hatena.ne.jp/whoopsidaisies/20140210111230&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;url&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140210/20140210111230.png&quot; alt=&quot;f:id:whoopsidaisies:20140210111230p:image:w275&quot; title=&quot;f:id:whoopsidaisies:20140210111230p:image:w275&quot; class=&quot;hatena-fotolife&quot; style=&quot;width:275px&quot; itemprop=&quot;image&quot;&gt;&lt;/a&gt;&lt;/span&gt;  &lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;a href=&quot;http://f.hatena.ne.jp/whoopsidaisies/20140210111034&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;url&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140210/20140210111034.png&quot; alt=&quot;f:id:whoopsidaisies:20140210111034p:image:w275&quot; title=&quot;f:id:whoopsidaisies:20140210111034p:image:w275&quot; class=&quot;hatena-fotolife&quot; style=&quot;width:275px&quot; itemprop=&quot;image&quot;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;すると，ツールボックスに「Plot」ができるので，Formに配置する．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140210/20140210111336.png&quot; alt=&quot;f:id:whoopsidaisies:20140210111336p:plain&quot; title=&quot;f:id:whoopsidaisies:20140210111336p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;FunctionSeries&lt;/h3&gt;
    &lt;p&gt;OxyPlotには，&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/bb549151(v=vs.110).aspx&quot;&gt;Func&amp;lt;double, double&amp;gt;&lt;/a&gt;のメソッドのグラフを描画してくれる&lt;a href=&quot;http://www.oxyplot.org/doc/API/OxyPlot.Series.FunctionSeries.html&quot;&gt;FunctionSeries&lt;/a&gt;クラスがあるのでその使い方を記す．&lt;br /&gt;
Func&amp;lt;double, double&amp;gt;という書き方になじみがない人もいるかもしれないので，とりあえず標準正規分布&lt;br /&gt;
&lt;img src=&quot;http://chart.apis.google.com/chart?cht=tx&amp;chl=f%5C%28x%5C%29%3D%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7Dexp%5C%28-%5Cfrac%7Bx%5E%7B2%7D%7D%7B2%7D%5C%29&quot; alt=&quot;f\(x\)=\frac{1}{\sqrt{2\pi}}exp\(-\frac{x^{2}}{2}\)&quot;/&gt;&lt;br /&gt;
を描くサンプルを以下に示す．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synType&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt; StandardNormalDistribution(&lt;span class=&quot;synType&quot;&gt;double&lt;/span&gt; x)
{
    &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; / Math.Sqrt(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * Math.PI) * Math.Exp(-x * x / &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;);
}

&lt;span class=&quot;synType&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; Form1_Load(&lt;span class=&quot;synType&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
{
    plot1.Model = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; OxyPlot.PlotModel { PlotType = OxyPlot.PlotType.XY };
    var series = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; OxyPlot.Series.FunctionSeries(
        StandardNormalDistribution,     &lt;span class=&quot;synComment&quot;&gt;// 引数double，戻り値doubleの関数&lt;/span&gt;
        -&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;,                             &lt;span class=&quot;synComment&quot;&gt;// x座標の最小値&lt;/span&gt;
        &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;,                              &lt;span class=&quot;synComment&quot;&gt;// x座標の最大値&lt;/span&gt;
        &lt;span class=&quot;synConstant&quot;&gt;0.01&lt;/span&gt;,                           &lt;span class=&quot;synComment&quot;&gt;// x座標の刻み幅&lt;/span&gt;
        &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;標準正規分布&amp;quot;&lt;/span&gt;);                &lt;span class=&quot;synComment&quot;&gt;// グラフタイトル&lt;/span&gt;
    plot1.Model.Series.Add(series);
}
&lt;/pre&gt;&lt;p&gt;実行すると以下のようなグラフが表示される．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140210/20140210114639.png&quot; alt=&quot;f:id:whoopsidaisies:20140210114639p:plain&quot; title=&quot;f:id:whoopsidaisies:20140210114639p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;StandardNormalDistributionという引数がdouble型，戻り値もdouble型の関数を定義している．これがFunc&amp;lt;double, double&amp;gt;のメソッドである．&lt;br /&gt;
これと，グラフ描画をしたい範囲をFunctionSeriesクラスのコンストラクタに渡してやるだけでグラフを描画してくれて非常に便利である．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ラムダ式による方法&lt;/h3&gt;
    &lt;p&gt;メソッドの部分を&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/bb397687.aspx&quot;&gt;&amp;#x30E9;&amp;#x30E0;&amp;#x30C0;&amp;#x5F0F;&lt;/a&gt;で表現することも当然出来るので，StandardNormalDistributionメソッドをわざわざ定義しないでも以下のように書くこともできる．（ここではラムダ式の説明は省略．わからない人は&lt;a href=&quot;http://ufcpp.net/study/csharp/sp3_lambda.html&quot;&gt;&amp;#x3053;&amp;#x3053;&amp;#x3089;&amp;#x306E;&amp;#x3078;&amp;#x3093;&amp;#x306E;&amp;#x30DA;&amp;#x30FC;&amp;#x30B8;&lt;/a&gt;を参照）&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;    var series = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; OxyPlot.Series.FunctionSeries(
        x =&amp;gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; / Math.Sqrt(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * Math.PI) * Math.Exp(-x * x / &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;),     &lt;span class=&quot;synComment&quot;&gt;// 引数double，戻り値doubleの関数&lt;/span&gt;
        -&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;,                             &lt;span class=&quot;synComment&quot;&gt;// x座標の最小値&lt;/span&gt;
        &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;,                              &lt;span class=&quot;synComment&quot;&gt;// x座標の最大値&lt;/span&gt;
        &lt;span class=&quot;synConstant&quot;&gt;0.01&lt;/span&gt;,                           &lt;span class=&quot;synComment&quot;&gt;// x座標の刻み幅&lt;/span&gt;
        &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;標準正規分布&amp;quot;&lt;/span&gt;);                &lt;span class=&quot;synComment&quot;&gt;// グラフタイトル&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;媒介変数表示された関数のグラフ描画&lt;/h3&gt;
    &lt;p&gt;これも簡単に出来るので例を示す．例として以下の&lt;a href=&quot;http://www.phoenix-c.or.jp/~tokioka/Epicycloid/Epicycloid.html&quot;&gt;&amp;#x30AB;&amp;#x30FC;&amp;#x30B8;&amp;#x30AA;&amp;#x30A4;&amp;#x30C9;&lt;/a&gt;を表示させてみる．&lt;br /&gt;
&lt;img src=&quot;http://chart.apis.google.com/chart?cht=tx&amp;chl=x%3Da%5C%282%5Ccos%5Ctheta%20-%20%5Ccos2%5Ctheta%5C%29&quot; alt=&quot;x=a\(2\cos\theta - \cos2\theta\)&quot;/&gt;&lt;br /&gt;
&lt;img src=&quot;http://chart.apis.google.com/chart?cht=tx&amp;chl=y%3Da%5C%282%5Csin%5Ctheta%20-%20%5Csin2%5Ctheta%5C%29&quot; alt=&quot;y=a\(2\sin\theta - \sin2\theta\)&quot;/&gt;&lt;/p&gt;&lt;p&gt;ソースコードは以下のようになる．（ラムダ式使用）&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;= &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; OxyPlot.PlotModel { PlotType = OxyPlot.PlotType.XY };
var series = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; OxyPlot.Series.FunctionSeries(
    t =&amp;gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * Math.Cos(t) - Math.Cos(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * t), &lt;span class=&quot;synComment&quot;&gt;// x座標の関数&lt;/span&gt;
    t =&amp;gt; &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * Math.Sin(t) - Math.Sin(&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * t), &lt;span class=&quot;synComment&quot;&gt;// y座標の関数&lt;/span&gt;
    &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;,                                      &lt;span class=&quot;synComment&quot;&gt;// tの最小値&lt;/span&gt;
    &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; * Math.PI,                            &lt;span class=&quot;synComment&quot;&gt;// tの最大値&lt;/span&gt;
    Math.PI / &lt;span class=&quot;synConstant&quot;&gt;32&lt;/span&gt;,                           &lt;span class=&quot;synComment&quot;&gt;// tの刻み幅&lt;/span&gt;
    &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;カージオイド&amp;quot;&lt;/span&gt;);                        &lt;span class=&quot;synComment&quot;&gt;// グラフタイトル&lt;/span&gt;
plot1.Model.Series.Add(series);
&lt;/pre&gt;&lt;p&gt;実行すると以下のようなグラフが表示される．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140210/20140210122606.png&quot; alt=&quot;f:id:whoopsidaisies:20140210122606p:plain&quot; title=&quot;f:id:whoopsidaisies:20140210122606p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;その他&lt;/h3&gt;
    &lt;p&gt;PlotTypeの設定によって極座標表示とかもできるがそれはまたの機会に．&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term=".NET" label=".NET" />
        
        <category term="Windows フォーム アプリケーション" label="Windows フォーム アプリケーション" />
        
        <category term="NuGet" label="NuGet" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/c758ce952e92b4d960fdae36cabfe5734186cb1c/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140210%2F20140210122606.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#で地球を表示する（vtkTexturedSphereSourceによる方法）</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/02/09/203407"/>
        <id>hatenablog://entry/12921228815718096784</id>
        <published>2014-02-09T20:34:07+09:00</published>
        <updated>2014-02-09T20:34:07+09:00</updated>        <summary type="html">VTKのvtkTexturedSphereSourceで球に世界地図のテクスチャを貼り付けることで地球を表示させる．テクスチャを使わずにvtkEarthSourceによって表示する方法は以下のページを参照． C#で地球を表示する（VTKのEarthSourceによる方法） - whoopsidaisies&#39;s diary ActiViz ActiVizは，3Dコンピュータグラフィックスの可視化ライブラリVTK（The Visualization ToolKit）のC＃ラッパである．NuGetからインストールできる．簡単な解説は以下のページを参照． C#で3Dモデル表示（VTKのC#ラッパAct…</summary>
        <content type="html">&lt;p&gt;VTKのvtkTexturedSphereSourceで球に世界地図のテクスチャを貼り付けることで地球を表示させる．&lt;/p&gt;&lt;p&gt;テクスチャを使わずにvtkEarthSourceによって表示する方法は以下のページを参照．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/02/09/185536&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2014%2F02%2F09%2F185536&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2014/02/09/185536&quot;&gt;C#&amp;#x3067;&amp;#x5730;&amp;#x7403;&amp;#x3092;&amp;#x8868;&amp;#x793A;&amp;#x3059;&amp;#x308B;&amp;#xFF08;VTK&amp;#x306E;EarthSource&amp;#x306B;&amp;#x3088;&amp;#x308B;&amp;#x65B9;&amp;#x6CD5;&amp;#xFF09; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ActiViz&lt;/h3&gt;
    &lt;p&gt;&lt;a href=&quot;http://www.kitware.com/opensource/avdownload.php&quot;&gt;ActiViz&lt;/a&gt;は，3Dコンピュータグラフィックスの可視化ライブラリ&lt;a href=&quot;http://www.vtk.org/&quot;&gt;VTK&amp;#xFF08;The Visualization ToolKit&amp;#xFF09;&lt;/a&gt;のC＃ラッパである．NuGetからインストールできる．簡単な解説は以下のページを参照．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/28/131053&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2013%2F12%2F28%2F131053&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/28/131053&quot;&gt;C#&amp;#x3067;3D&amp;#x30E2;&amp;#x30C7;&amp;#x30EB;&amp;#x8868;&amp;#x793A;&amp;#xFF08;VTK&amp;#x306E;C#&amp;#x30E9;&amp;#x30C3;&amp;#x30D1;ActiViz&amp;#x306B;&amp;#x3088;&amp;#x308B;&amp;#x65B9;&amp;#x6CD5;&amp;#xFF09; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;RenderWindowControl&lt;/h3&gt;
    &lt;p&gt;NuGetからActiVizをインストールし，RenderWindowControlをフォームに追加する．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;vtkTexturedSphereSource&lt;/h3&gt;
    &lt;p&gt;VTKには&lt;a href=&quot;http://www.vtk.org/doc/nightly/html/classvtkTexturedSphereSource.html&quot;&gt;vtkTexturedSphereSource&lt;/a&gt;という，テクスチャを貼り付けることが出来る球オブジェクトのクラスがあるためそれを利用する．ソースコードは以下のようになる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;sing (var sphere = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkTexturedSphereSource())
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var texture = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkTexture())
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var image = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkPNGReader())
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var mapper = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkCompositePolyDataMapper())
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var actor = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkActor())
{
    &lt;span class=&quot;synComment&quot;&gt;// 球の滑らかさ（数字が多いほど分割数が多く滑らかになる）&lt;/span&gt;
    sphere.SetThetaResolution(&lt;span class=&quot;synConstant&quot;&gt;64&lt;/span&gt;);
    sphere.SetPhiResolution(&lt;span class=&quot;synConstant&quot;&gt;64&lt;/span&gt;);
    mapper.SetInputConnection(sphere.GetOutputPort());
    actor.SetMapper(mapper);

    &lt;span class=&quot;synComment&quot;&gt;// 世界地図画像の読み込みとテクスチャの設定&lt;/span&gt;
    image.SetFileName(&lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;WorldMap_ja.png&amp;quot;&lt;/span&gt;);
    texture.SetInputConnection(image.GetOutputPort());                
    actor.SetTexture(texture);

    renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(actor);
}
&lt;/pre&gt;&lt;p&gt;実行すると以下のように地球が表示される．世界地図画像は&lt;a href=&quot;http://ja.wikipedia.org/wiki/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB:WorldMap_ja.png&quot;&gt;&amp;#x30A6;&amp;#x30A3;&amp;#x30AD;&amp;#x30DA;&amp;#x30C7;&amp;#x30A3;&amp;#x30A2;&lt;/a&gt;にあったものを使った．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140209/20140209202615.png&quot; alt=&quot;f:id:whoopsidaisies:20140209202615p:plain&quot; title=&quot;f:id:whoopsidaisies:20140209202615p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;以下のように拡大表示もできるが，この方法だとベクターグラフィックの読み込みが（たぶん）できないので拡大表示する際は何かしら工夫が必要そう．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140209/20140209203055.png&quot; alt=&quot;f:id:whoopsidaisies:20140209203055p:plain&quot; title=&quot;f:id:whoopsidaisies:20140209203055p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/1602e1c38177c5415c18a44a13fee5542c5f3f06/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140209%2F20140209202615.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
    <entry>
        <title>C#で地球を表示する（VTKのEarthSourceによる方法）</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/02/09/185536"/>
        <id>hatenablog://entry/12921228815718088740</id>
        <published>2014-02-09T18:55:36+09:00</published>
        <updated>2014-02-09T18:55:36+09:00</updated>        <summary type="html">C#でVTKのvtkEarthSourceクラスによって地球を表示させる． ActiViz ActiVizは，3Dコンピュータグラフィックスの可視化ライブラリVTK（The Visualization ToolKit）のC＃ラッパである．NuGetからインストールできる．簡単な解説は以下のページを参照． C#で3Dモデル表示（VTKのC#ラッパActiVizによる方法） - whoopsidaisies&#39;s diary RenderWindowControl NuGetからActiVizをインストールし，RenderWindowControlをフォームに追加する． vtkEarthSource…</summary>
        <content type="html">&lt;p&gt;C#でVTKのvtkEarthSourceクラスによって地球を表示させる．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ActiViz&lt;/h3&gt;
    &lt;p&gt;&lt;a href=&quot;http://www.kitware.com/opensource/avdownload.php&quot;&gt;ActiViz&lt;/a&gt;は，3Dコンピュータグラフィックスの可視化ライブラリ&lt;a href=&quot;http://www.vtk.org/&quot;&gt;VTK&amp;#xFF08;The Visualization ToolKit&amp;#xFF09;&lt;/a&gt;のC＃ラッパである．NuGetからインストールできる．簡単な解説は以下のページを参照．&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/28/131053&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2013%2F12%2F28%2F131053&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/12/28/131053&quot;&gt;C#&amp;#x3067;3D&amp;#x30E2;&amp;#x30C7;&amp;#x30EB;&amp;#x8868;&amp;#x793A;&amp;#xFF08;VTK&amp;#x306E;C#&amp;#x30E9;&amp;#x30C3;&amp;#x30D1;ActiViz&amp;#x306B;&amp;#x3088;&amp;#x308B;&amp;#x65B9;&amp;#x6CD5;&amp;#xFF09; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;RenderWindowControl&lt;/h3&gt;
    &lt;p&gt;NuGetからActiVizをインストールし，RenderWindowControlをフォームに追加する．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;vtkEarthSource&lt;/h3&gt;
    &lt;p&gt;VTKには&lt;a href=&quot;http://www.vtk.org/doc/release/5.0/html/a01341.html&quot;&gt;vtkEarthSource&lt;/a&gt;という，地球が表示されるオブジェクトがあるので使う．ソースコードは以下のようになる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var earth = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkEarthSource())
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var mapper = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkCompositePolyDataMapper())
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; (var actor = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; Kitware.VTK.vtkActor())
{
    mapper.SetInputConnection(earth.GetOutputPort());
    actor.SetMapper(mapper);
    renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer().AddActor(actor);
}
&lt;/pre&gt;&lt;p&gt;実行すると以下のように地球が表示される．ドラッグで視点変更が出来る．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140209/20140209185406.png&quot; alt=&quot;f:id:whoopsidaisies:20140209185406p:plain&quot; title=&quot;f:id:whoopsidaisies:20140209185406p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/36957cfbc32aac973263326ed62ca6f174d8794e/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140209%2F20140209185406.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C++でLINQライクな処理（LINQ for C++による方法）</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/01/17/011213"/>
        <id>hatenablog://entry/12921228815716655711</id>
        <published>2014-01-17T01:12:13+09:00</published>
        <updated>2014-01-17T01:12:13+09:00</updated>        <summary type="html">LINQ for C++ LINQは.NET Framework3.5から組み込まれた機能で，C#等の言語でSQLのデータベース操作のようなことを可能とする．「C# is LINQ」と言う方までいほどに便利な機能．しかし，C++/CLIはLINQに対応する予定はないとのこと．そこで，LINQに似た機能をC++に提供してくれるのがLINQ for C++である．というわけでLINQ for C++を使ってみる． 導入 LINQ for C++はヘッダファイルひとつで実装されているので，以下のページからダウンロードしてきてインクルードするだけで使用できる．NuGetからのインストールも取得可能であ…</summary>
        <content type="html">
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;LINQ for C++&lt;/h3&gt;
    &lt;p&gt;&lt;a href=&quot;http://ja.wikipedia.org/wiki/%E7%B5%B1%E5%90%88%E8%A8%80%E8%AA%9E%E3%82%AF%E3%82%A8%E3%83%AA&quot;&gt;LINQ&lt;/a&gt;は.NET Framework3.5から組み込まれた機能で，C#等の言語でSQLのデータベース操作のようなことを可能とする．「&lt;a href=&quot;http://www.slideshare.net/neuecc/the-history-of-linq/19&quot;&gt;C# is LINQ&lt;/a&gt;」と言う方までいほどに便利な機能．&lt;/p&gt;&lt;p&gt;しかし，&lt;a href=&quot;http://ja.wikipedia.org/wiki/%E7%B5%B1%E5%90%88%E8%A8%80%E8%AA%9E%E3%82%AF%E3%82%A8%E3%83%AA&quot;&gt;C++/CLI&amp;#x306F;LINQ&amp;#x306B;&amp;#x5BFE;&amp;#x5FDC;&amp;#x3059;&amp;#x308B;&amp;#x4E88;&amp;#x5B9A;&amp;#x306F;&amp;#x306A;&amp;#x3044;&lt;/a&gt;とのこと．そこで，LINQに似た機能をC++に提供してくれるのが&lt;a href=&quot;http://cpplinq.codeplex.com/&quot;&gt;LINQ for C++&lt;/a&gt;である．というわけでLINQ for C++を使ってみる．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;導入&lt;/h3&gt;
    &lt;p&gt;LINQ for C++はヘッダファイルひとつで実装されているので，以下のページからダウンロードしてきてインクルードするだけで使用できる．NuGetからのインストールも取得可能である．&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://cpplinq.codeplex.com/&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fcpplinq.codeplex.com%2F&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://cpplinq.codeplex.com/&quot;&gt;LINQ for C++ - Home&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;使用例１&lt;/h3&gt;
    &lt;p&gt;以下に使用例を示す．LINQ for C++を使って，テストの成績のうち国語と英語がともに５０点以上の人のリストを取得している．&lt;/p&gt;&lt;p&gt;普通の配列に対して使うことが出来る．コード補完も微妙だし，型明記しなくちゃいけないし，メソッド形式ないしでC#のLINQほど軽快には書けないものの，便利ではある．&lt;/p&gt;
&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;cpplinq.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; main()
{
	&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; cpplinq;

	&lt;span class=&quot;synType&quot;&gt;struct&lt;/span&gt; Seiseki
	{
		&lt;span class=&quot;synType&quot;&gt;char&lt;/span&gt; Name[&lt;span class=&quot;synConstant&quot;&gt;256&lt;/span&gt;];
		&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; Kokugo;
		&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; Sansuu;
		&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; Eigo;
		&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; Rika;
		&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; Shakai;
	};

	Seiseki seisekiList[] = 
	{
		{&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Yamada&amp;quot;&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;98&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;78&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;61&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;83&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;70&lt;/span&gt;},
		{&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Tanaka&amp;quot;&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;20&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;33&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;16&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;39&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;48&lt;/span&gt;},
		{&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Yoshida&amp;quot;&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;72&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;65&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;92&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;13&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;26&lt;/span&gt;},
		{&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Suzuki&amp;quot;&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;49&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;82&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;55&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;11&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;96&lt;/span&gt;},
		{&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Sasaki&amp;quot;&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;83&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;47&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;61&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;23&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;60&lt;/span&gt;}
	};
	
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; result = from_array(seisekiList)
		&amp;gt;&amp;gt; where([](Seiseki s) &lt;span class=&quot;synError&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; s.Kokugo &amp;gt; &lt;span class=&quot;synConstant&quot;&gt;50&lt;/span&gt; &amp;amp;&amp;amp; s.Eigo &amp;gt; &lt;span class=&quot;synConstant&quot;&gt;50&lt;/span&gt;;})
		&amp;gt;&amp;gt; to_vector();

	&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; result.size();  ++ i)
		printf(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt; : 国語&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt; 英語&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;%d\n&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;, result[i].Name, result[i].Kokugo, result[i].Eigo);
}
&lt;/pre&gt;&lt;p&gt;結果は以下のように表示される．&lt;/p&gt;
&lt;pre class=&quot;code&quot; data-lang=&quot;&quot; data-unlink&gt;Yamada : 国語98 英語61
Yoshida : 国語72 英語92
Sasaki : 国語83 英語61&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;使用例２&lt;/h3&gt;
    &lt;p&gt;無理やりOpenCVで使ってみる．BRISKで特徴点抽出し，オリエンテーションの向きによって表示する際の色を変えている．&lt;/p&gt;
&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/opencv.hpp&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;cpplinq.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; main()
{
	&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; cpplinq;

	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; image = cv::imread(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Penguins.jpg&amp;quot;&lt;/span&gt;);

	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; detector = cv::FeatureDetector::create(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;BRISK&amp;quot;&lt;/span&gt;);
	std::vector&amp;lt;cv::KeyPoint&amp;gt; keyPoints;
	detector-&amp;gt;detect(image, keyPoints);
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; key1 = from(keyPoints)
		&amp;gt;&amp;gt; where([](cv::KeyPoint k) &lt;span class=&quot;synError&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; &amp;lt;= k.angle &amp;amp;&amp;amp; k.angle &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;90&lt;/span&gt;;})
		&amp;gt;&amp;gt; to_vector();
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; key2 = from(keyPoints)
		&amp;gt;&amp;gt; where([](cv::KeyPoint k) &lt;span class=&quot;synError&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;90&lt;/span&gt; &amp;lt;= k.angle &amp;amp;&amp;amp; k.angle &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;180&lt;/span&gt;;})
		&amp;gt;&amp;gt; to_vector();
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; key3 = from(keyPoints)
		&amp;gt;&amp;gt; where([](cv::KeyPoint k) &lt;span class=&quot;synError&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;180&lt;/span&gt; &amp;lt;= k.angle &amp;amp;&amp;amp; k.angle &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;270&lt;/span&gt;;})
		&amp;gt;&amp;gt; to_vector();
	&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; key4 = from(keyPoints)
		&amp;gt;&amp;gt; where([](cv::KeyPoint k) &lt;span class=&quot;synError&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;270&lt;/span&gt; &amp;lt;= k.angle &amp;amp;&amp;amp; k.angle &amp;lt; &lt;span class=&quot;synConstant&quot;&gt;360&lt;/span&gt;;})
		&amp;gt;&amp;gt; to_vector();

	cv::drawKeypoints(image, key1, image, cv::Scalar(&lt;span class=&quot;synConstant&quot;&gt;255&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
	cv::drawKeypoints(image, key2, image, cv::Scalar(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;255&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
	cv::drawKeypoints(image, key3, image, cv::Scalar(&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;255&lt;/span&gt;), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
	cv::drawKeypoints(image, key4, image, cv::Scalar(&lt;span class=&quot;synConstant&quot;&gt;255&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;255&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
	cv::imshow(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Key Point&amp;quot;&lt;/span&gt;, image);
	&lt;span class=&quot;synStatement&quot;&gt;while&lt;/span&gt;(cv::waitKey(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;) == -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;);
}
&lt;/pre&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140117/20140117010914.png&quot; alt=&quot;f:id:whoopsidaisies:20140117010914p:plain&quot; title=&quot;f:id:whoopsidaisies:20140117010914p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="Programming" label="Programming" />
        
        <category term="C++" label="C++" />
        
        <category term="NuGet" label="NuGet" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/7294e3c4a161713f940804140580bcf8f65a1381/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140117%2F20140117010914.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C# 名前付きの色一覧を配列に取得してRGB値をDataGridViewに表示する</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/01/15/202429"/>
        <id>hatenablog://entry/12921228815716589098</id>
        <published>2014-01-15T20:24:29+09:00</published>
        <updated>2014-01-15T20:24:29+09:00</updated>        <summary type="html">Color構造体 .NET FrameworkのColor構造体はRGB値で色の指定もできるが，あらかじめRGB値が指定されていて名前を指定して使える色がある．「Color.Red」とか「Color.Green」といった感じで使うことが出来る．本記事では，名前が付いた色の一覧を取得してColor構造体の配列に取得，さらにRGB値と色をDataGridViewに表示する方法を紹介する． 名前付きの色の取得 名前付きの色は，Color構造体の静的プロパティとして定義されている．色の一覧をColor構造体の配列に格納するコードは以下のようになる． var colors = typeof(Color)…</summary>
        <content type="html">
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Color構造体&lt;/h3&gt;
    &lt;p&gt;.NET Frameworkの&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.drawing.color(v=vs.110).aspx&quot;&gt;Color&amp;#x69CB;&amp;#x9020;&amp;#x4F53;&lt;/a&gt;はRGB値で色の指定もできるが，あらかじめRGB値が指定されていて名前を指定して使える色がある．「Color.Red」とか「Color.Green」といった感じで使うことが出来る．&lt;/p&gt;&lt;p&gt;本記事では，名前が付いた色の一覧を取得してColor構造体の配列に取得，さらにRGB値と色をDataGridViewに表示する方法を紹介する．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;名前付きの色の取得&lt;/h3&gt;
    &lt;p&gt;名前付きの色は，Color構造体の静的プロパティとして定義されている．色の一覧をColor構造体の配列に格納するコードは以下のようになる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;var colors = &lt;span class=&quot;synStatement&quot;&gt;typeof&lt;/span&gt;(Color).GetProperties(BindingFlags.Static | BindingFlags.Public)
    .Select(p =&amp;gt; Color.FromName(p.Name))
    .ToList();
&lt;/pre&gt;&lt;p&gt;１行目では，&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/kyaxdd3x(v=vs.110).aspx&quot;&gt;GetProperties&lt;/a&gt;メソッドを使って，Color構造体のパブリックな静的プロパティの型情報の一覧を取得している．&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.reflection.bindingflags(v=vs.110).aspx&quot;&gt;BindingFlags&lt;/a&gt;構造体を使って取得するプロパティの検索方法を指定できるが，StaticとPublicを指定することでパブリックな静的プロパティを取得している．&lt;/p&gt;&lt;p&gt;２行目では，&lt;a href=&quot;http://ufcpp.net/study/csharp/sp3_linq.html&quot;&gt;LINQ&lt;/a&gt;の&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/bb548891(v=vs.110).aspx&quot;&gt;Select&lt;/a&gt;メソッドと&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.drawing.color.fromname(v=vs.110).aspx:Color.FromaName&quot;&gt;http://msdn.microsoft.com/ja-jp/library/system.drawing.color.fromname(v=vs.110).aspx:Color.FromaName&lt;/a&gt;メソッドを使って色の名前から，その色のColorオブジェクトを生成している．&lt;/p&gt;&lt;p&gt;３行目で，結果をList&lt;Color&gt;に変換している．（ListとかArrayとかに変換したほうが後の処理が楽なので）&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;DataGridViewで表示&lt;/h3&gt;
    &lt;p&gt;取得した色の一覧を&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridview(v=vs.110).aspx&quot;&gt;DataGridView&lt;/a&gt;コントロールに表示する．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;dataGridView1.DataSource = colors;
&lt;/pre&gt;&lt;p&gt;上記の一行を追加すると以下のように色の名前とRGB値が表示される．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140115/20140115195242.png&quot; alt=&quot;f:id:whoopsidaisies:20140115195242p:plain&quot; title=&quot;f:id:whoopsidaisies:20140115195242p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;表示するプロパティの選択&lt;/h3&gt;
    &lt;p&gt;上の画像だと「IsKnownColor」とかの余計なプロパティも表示されているので，表示しないようにする．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (DataGridViewColumn col &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; dataGridView1.Columns)
    &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; (col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;R&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;G&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;)
        col.Visible = &lt;span class=&quot;synConstant&quot;&gt;false&lt;/span&gt;;
&lt;/pre&gt;&lt;p&gt;DataGridViewの各列は&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridviewcolumn.visible(v=vs.110).aspx&quot;&gt;Visible&lt;/a&gt;プロパティによって表示・非表示を切り替えられるので，RGBと名前以外の列を非表示に設定している．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140115/20140115200155.png&quot; alt=&quot;f:id:whoopsidaisies:20140115200155p:plain&quot; title=&quot;f:id:whoopsidaisies:20140115200155p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;セルの色付け&lt;/h3&gt;
    &lt;p&gt;名前とRGB値だけだとどんな色か想像がつきにくいので，セルに色を付ける．ついでに名前が表示されている列を先頭にする．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; colors.Count; ++i)
    dataGridView1[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;, i].Style.BackColor = colors[i];
dataGridView1.Columns[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;].DisplayIndex = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;;
&lt;/pre&gt;&lt;p&gt;DataGridViewの各&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridviewcell(v=vs.110).aspx&quot;&gt;&amp;#x30BB;&amp;#x30EB;&lt;/a&gt;は&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridviewcell.style(v=vs.110).aspx&quot;&gt;Style&lt;/a&gt;プロパティによって&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridviewcellstyle(v=vs.110).aspx&quot;&gt;&amp;#x8272;&amp;#x3084;&amp;#x30D5;&amp;#x30A9;&amp;#x30F3;&amp;#x30C8;&amp;#x7B49;&amp;#x306E;&amp;#x66F8;&amp;#x5F0F;&lt;/a&gt;を指定出来る．ここでは&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridviewcellstyle.backcolor(v=vs.110).aspx&quot;&gt;BackColor&lt;/a&gt;プロパティによって背景色を指定している．&lt;/p&gt;&lt;p&gt;また，&lt;a href=&quot;http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridviewcolumn.displayindex(v=vs.110).aspx&quot;&gt;DisplayIndex&lt;/a&gt;プロパティによって名前の表示列を先頭にしている．&lt;/p&gt;&lt;p&gt;実行すると以下のように名前のセルに色がついて表示される．（Transparentのところは後ろのウィンドウが表示されている．）&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140115/20140115201854.png&quot; alt=&quot;f:id:whoopsidaisies:20140115201854p:plain&quot; title=&quot;f:id:whoopsidaisies:20140115201854p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;ソースコード&lt;/h3&gt;
    &lt;p&gt;上記コードをまとめると以下のようになる．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;var colors = &lt;span class=&quot;synStatement&quot;&gt;typeof&lt;/span&gt;(Color).GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)
    .Select(p =&amp;gt; Color.FromName(p.Name))
    .ToList();

dataGridView1.DataSource = colors;

&lt;span class=&quot;synStatement&quot;&gt;foreach&lt;/span&gt; (DataGridViewColumn col &lt;span class=&quot;synStatement&quot;&gt;in&lt;/span&gt; dataGridView1.Columns)
    &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; (col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;R&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;G&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt; &amp;amp;&amp;amp; col.Name != &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;)
        col.Visible = &lt;span class=&quot;synConstant&quot;&gt;false&lt;/span&gt;;

&lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; i = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;; i &amp;lt; colors.Count; ++i)
    dataGridView1[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;, i].Style.BackColor = colors[i];
dataGridView1.Columns[&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;].DisplayIndex = &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term=".NET" label=".NET" />
        
        <category term="Windows フォーム アプリケーション" label="Windows フォーム アプリケーション" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/cb59c686feb145d0f3adb673adeb7e552b31aa86/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140115%2F20140115201854.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#でOpenCVを使う（C++/CLIによる方法）</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/01/12/113050"/>
        <id>hatenablog://entry/12921228815716339920</id>
        <published>2014-01-12T11:30:50+09:00</published>
        <updated>2014-01-12T11:30:50+09:00</updated>        <summary type="html">OpenCVラッパクラス C#でOpenCVを手軽に使うにはOpenCvSharpをつかう その17(NuGetで導入) - schima.hatenablog.com C#でOpenCVを動かす～NuGetでOpenCV.Netをインストール - whoopsidaisies&#39;s diaryのページのように，NuGetからC#ラッパをインストールして使う方法があるが，必要な機能がラッピングされていないことがある．このページでは，C++/CLIでOpenCVの必要な機能だけ持つラッパクラスを自分で作り，C#から呼び出す方法を紹介する． C++/CLI 通常のC++のライブラリをC#から呼び出そ…</summary>
        <content type="html">
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;OpenCVラッパクラス&lt;/h3&gt;
    &lt;p&gt;C#でOpenCVを手軽に使うには&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://schima.hatenablog.com/entry/2013/12/15/110513&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fschima.hatenablog.com%2Fentry%2F2013%2F12%2F15%2F110513&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://schima.hatenablog.com/entry/2013/12/15/110513&quot;&gt;OpenCvSharp&amp;#x3092;&amp;#x3064;&amp;#x304B;&amp;#x3046; &amp;#x305D;&amp;#x306E;17(NuGet&amp;#x3067;&amp;#x5C0E;&amp;#x5165;) - schima.hatenablog.com&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/10/25/005953&quot;&gt;&lt;img src=&quot;http://cdn-ak.favicon.st-hatena.com/?url=http%3A%2F%2Fwhoopsidaisies.hatenablog.com%2Fentry%2F2013%2F10%2F25%2F005953&quot; alt=&quot;&quot; class=&quot;http-favicon&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://whoopsidaisies.hatenablog.com/entry/2013/10/25/005953&quot;&gt;C#&amp;#x3067;OpenCV&amp;#x3092;&amp;#x52D5;&amp;#x304B;&amp;#x3059;&amp;#xFF5E;NuGet&amp;#x3067;OpenCV.Net&amp;#x3092;&amp;#x30A4;&amp;#x30F3;&amp;#x30B9;&amp;#x30C8;&amp;#x30FC;&amp;#x30EB; - whoopsidaisies&amp;#39;s diary&lt;/a&gt;&lt;/p&gt;&lt;p&gt;のページのように，NuGetからC#ラッパをインストールして使う方法があるが，必要な機能がラッピングされていないことがある．&lt;/p&gt;&lt;p&gt;このページでは，C++/CLIでOpenCVの必要な機能だけ持つラッパクラスを自分で作り，C#から呼び出す方法を紹介する．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;C++/CLI&lt;/h3&gt;
    &lt;p&gt;通常のC++のライブラリをC#から呼び出そうとするとDllImport属性で宣言が必要だったりして面倒であるが，&lt;a href=&quot;http://ja.wikipedia.org/wiki/C%2B%2B/CLI&quot;&gt;C++/CLI&lt;/a&gt;で作ったDLLであれば参照に追加するだけで使用できる．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;手順&lt;/h3&gt;
    &lt;p&gt;手順は以下の通りである．&lt;/p&gt;

&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;C#プロジェクト作成&lt;/h5&gt;
    &lt;p&gt;実行されるC#のプロジェクト&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;C++/CLIのDLL用プロジェクト作成&lt;/h5&gt;
    &lt;p&gt;OpenCVをラップするクラス用のプロジェクト&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;プロジェクトの参照の設定&lt;/h5&gt;
    &lt;p&gt;作成したクラスをC＃から読み込むための設定&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;OpenCVのインストール&lt;/h5&gt;
    &lt;p&gt;OpenCVのインストール&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;C++/CLIでラッパクラスの作成&lt;/h5&gt;
    &lt;p&gt;OpenCVによる処理部分の実装&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;C#のプロジェクトの出力パスの変更&lt;/h5&gt;
    &lt;p&gt;OpenCVのDLLの場所とかの関係上の設定&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h5&gt;C#から呼び出す&lt;/h5&gt;
    &lt;p&gt;C#からの呼び出し部分とGUIの実装&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;以下に各手順の詳細を記す．&lt;/p&gt;

&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;C#プロジェクト作成&lt;/h3&gt;
    &lt;p&gt;Visual Studioで新しいプロジェクトを作成する．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112101313.png&quot; alt=&quot;f:id:whoopsidaisies:20140112101313p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112101313p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;C++/CLIのDLL用プロジェクト作成&lt;/h3&gt;
    &lt;p&gt;ソリューションを右クリックして，「追加」の「新しいプロジェクト(N)...」でC++/CLIのDLL作成用のプロジェクトを作成する．「Visual C++」の「CLR」の「クラス ライブラリ」を選択．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112101334.png&quot; alt=&quot;f:id:whoopsidaisies:20140112101334p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112101334p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;プロジェクトの参照の設定&lt;/h3&gt;
    &lt;p&gt;C++/CLIで作成したDLLをC#から呼び出すための参照設定を行う．C#のプロジェクト内の「参照設定」を右クリックし「参照の追加(R)...」を選択する．開いたダイアログで「ソリューション」の「プロジェクト」を選択し，C++/CLIのプロジェクトの名前のところにチェックを入れる．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112101620.png&quot; alt=&quot;f:id:whoopsidaisies:20140112101620p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112101620p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112102324.png&quot; alt=&quot;f:id:whoopsidaisies:20140112102324p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112102324p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;OpenCVのインストール&lt;/h3&gt;
    &lt;p&gt;C++/CLIのプロジェクトを右クリックし「NuGet パッケージの管理」を選択．ダイアログで「オンライン」を選択し，検索窓で「OpenCV」を検索，インストールする．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112101806.png&quot; alt=&quot;f:id:whoopsidaisies:20140112101806p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112101806p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;C#のプロジェクトの出力パスの変更&lt;/h3&gt;
    &lt;p&gt;NuGetでインストールしたOpenCVのDLLが，C#プロジェクトで作成した実行ファイルから参照できる位置に配置されないため，実行ファイルの出力パスを変えてやる．C#のプロジェクトを右クリックし「プロパティ(R)」を選択．「ビルド」の「出力パス」を「..\Debug\」に変える（Releaseモードなら..\Release\）．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112110351.png&quot; alt=&quot;f:id:whoopsidaisies:20140112110351p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112110351p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
この手順を忘れると，実行時に以下のようなエラーメッセージが表示されてOpenCVの呼び出しに失敗する．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112110400.png&quot; alt=&quot;f:id:whoopsidaisies:20140112110400p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112110400p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;C++/CLIでラッパクラスの作成&lt;/h3&gt;
    &lt;p&gt;C++/CLIでOpenCVの処理のコードを書く．C++/CLIのプロジェクトを作成したときに色々とファイルが生成されているので，そのうちの「OpenCvClrLibrary.h」（プロジェクト名.h）を以下のようにする．画像をファイルから読み込んで，BRISK特徴点を抽出して表示するサンプルである．&lt;/p&gt;
&lt;pre class=&quot;code lang-cpp&quot; data-lang=&quot;cpp&quot; data-unlink&gt;&lt;span class=&quot;synComment&quot;&gt;// OpenCvClrLibrary.h&lt;/span&gt;

&lt;span class=&quot;synPreProc&quot;&gt;#pragma once&lt;/span&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;lt;opencv2/opencv.hpp&amp;gt;&lt;/span&gt;

&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; System;

&lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; OpenCvClrLibrary {

	&lt;span class=&quot;synStatement&quot;&gt;public&lt;/span&gt; ref &lt;span class=&quot;synType&quot;&gt;class&lt;/span&gt; TestClass
	{
	&lt;span class=&quot;synStatement&quot;&gt;public&lt;/span&gt;:
		&lt;span class=&quot;synType&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; TestMethod()
		{
			&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; image = cv::imread(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;Penguins.jpg&amp;quot;&lt;/span&gt;);

			&lt;span class=&quot;synType&quot;&gt;auto&lt;/span&gt; brisk = cv::BRISK();
			std::vector&amp;lt;cv::KeyPoint&amp;gt; keyPoint;
			brisk.detect(image, keyPoint);
			cv::drawKeypoints(image, keyPoint, image);

			cv::imshow(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;image&amp;quot;&lt;/span&gt;, image);
			&lt;span class=&quot;synStatement&quot;&gt;while&lt;/span&gt; (cv::waitKey(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;) == -&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;);
			cv::destroyAllWindows();
		}
	};
}
&lt;/pre&gt;&lt;p&gt;「ref class」はC++/CLI用のクラス．詳細は省略するが，こういう書き方をすることでC#でそのまま使えるクラスを作れる．&lt;br /&gt;
「auto」はc++11から追加された機能で，変数の初期値から型推論を行ってくれる．Visual Studio 2012以降では使えるみたい．横に長くなりがちなOpenCV（に限らないけど）のコードではこれを使えるのは嬉しい．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;C#から呼び出す&lt;/h3&gt;
    &lt;p&gt;C#から上記の特徴点抽出処理を呼び出すコードを以下のように書く．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;synStatement&quot;&gt;using&lt;/span&gt; System.Windows.Forms;

&lt;span class=&quot;synType&quot;&gt;namespace&lt;/span&gt; OpenCvFromCSharp
{
    &lt;span class=&quot;synType&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;partial&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;class&lt;/span&gt; Form1 : Form
    {
        &lt;span class=&quot;synType&quot;&gt;public&lt;/span&gt; Form1()
        {
            InitializeComponent();
        }

        &lt;span class=&quot;synType&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;void&lt;/span&gt; button1_Click(&lt;span class=&quot;synType&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            OpenCvClrLibrary.TestClass.TestMethod();
        }
    }
}
&lt;/pre&gt;&lt;p&gt;Buttonコントロールを配置して，クリックすると特徴点が書き込まれた画像が以下のように表示される．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140112/20140112104341.png&quot; alt=&quot;f:id:whoopsidaisies:20140112104341p:plain&quot; title=&quot;f:id:whoopsidaisies:20140112104341p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term=".NET" label=".NET" />
        
        <category term="OpenCV" label="OpenCV" />
        
        <category term="NuGet" label="NuGet" />
        
        <category term="C++" label="C++" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/9ee4fa2ea372627df3a2ac20d24346646c3a0986/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140112%2F20140112104341.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
    
    
    <entry>
        <title>C#でAI，PSD，EPS，SVG，PDF等の画像ファイルを開く（ImageMagickのC#ラッパMagick.NETによる方法）</title>
        <link href="https://whoopsidaisies.hatenablog.com/entry/2014/01/08/213252"/>
        <id>hatenablog://entry/12921228815716075117</id>
        <published>2014-01-08T21:32:52+09:00</published>
        <updated>2014-01-08T21:32:53+09:00</updated>        <summary type="html">Magick.NET 100種類以上の画像を操作したり表示したりできるライブラリImageMagickのC#ラッパMagick.NETを使って，C#でAI，PSD，EPS，SVG，PDF等の画像ファイルを開く． インストール NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「Magick.NET」を検索してインストール． プラットフォームを変える プロジェクトのプラットフォームをインストールしたパッケージ（「x64」か「x86」）に変える．「Any CPU」だと動かない場合があるので注意． サンプルコード 以下にepsファイ…</summary>
        <content type="html">
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;Magick.NET&lt;/h3&gt;
    &lt;p&gt;100種類以上の画像を操作したり表示したりできるライブラリ&lt;a href=&quot;http://www.imagemagick.org/script/index.php&quot;&gt;ImageMagick&lt;/a&gt;のC#ラッパ&lt;a href=&quot;https://magick.codeplex.com/&quot;&gt;Magick.NET&lt;/a&gt;を使って，C#でAI，PSD，EPS，SVG，PDF等の画像ファイルを開く．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;インストール&lt;/h3&gt;
    &lt;p&gt;NuGet経由でインストール可能．プロジェクトを右クリックして「NuGetパッケージの管理」を選択する．オンラインから「Magick.NET」を検索してインストール．&lt;/p&gt;&lt;p&gt;&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140108/20140108210712.png&quot; alt=&quot;f:id:whoopsidaisies:20140108210712p:plain&quot; title=&quot;f:id:whoopsidaisies:20140108210712p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;プラットフォームを変える&lt;/h3&gt;
    &lt;p&gt;プロジェクトのプラットフォームをインストールしたパッケージ（「x64」か「x86」）に変える．「Any CPU」だと動かない場合があるので注意．&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot;&gt;
    &lt;h3&gt;サンプルコード&lt;/h3&gt;
    &lt;p&gt;以下にepsファイルを開いて，PictureBoxに表示するサンプルを示す．ファイル名の部分を変えれば，eps以外のファイルも読み込むことが出来る．&lt;/p&gt;
&lt;pre class=&quot;code lang-cs&quot; data-lang=&quot;cs&quot; data-unlink&gt;var magickImage = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ImageMagick.MagickImage(
    &lt;span class=&quot;synSpecial&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;blossom tree.eps&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ImageMagick.MagickReadSettings() { Density = &lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt; ImageMagick.MagickGeometry(&lt;span class=&quot;synConstant&quot;&gt;300&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;300&lt;/span&gt;) });
pictureBox1.Image = magickImage.ToBitmap();
&lt;/pre&gt;&lt;p&gt;ImageMagick.MagickGeometry(300, 300)の数字の部分を大きくすると，AI，EPS，PDF等のベクター画像の読み込み後の解像度を高くすることが出来る．&lt;/p&gt;&lt;p&gt;以下のように，ベクター画像を高解像度にすると拡大してもきれいに表示出来る．&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140108/20140108211811.jpg&quot; alt=&quot;f:id:whoopsidaisies:20140108211811j:plain&quot; title=&quot;f:id:whoopsidaisies:20140108211811j:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt;&lt;img src=&quot;http://cdn-ak.f.st-hatena.com/images/fotolife/w/whoopsidaisies/20140108/20140108211819.png&quot; alt=&quot;f:id:whoopsidaisies:20140108211819p:plain&quot; title=&quot;f:id:whoopsidaisies:20140108211819p:plain&quot; class=&quot;hatena-fotolife&quot; itemprop=&quot;image&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;/div&gt;</content>        
        <category term="C#" label="C#" />
        
        <category term="Programming" label="Programming" />
        
        <category term=".NET" label=".NET" />
        
        <category term="NuGet" label="NuGet" />
        
        <link rel="enclosure" href="https://cdn.image.st-hatena.com/image/scale/258ea091e32e244a48cae106f89e2dcab52887eb/backend=imagemagick;version=1;width=1300/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fw%2Fwhoopsidaisies%2F20140108%2F20140108211819.png" type="image/png" length="0" />

        <author>
            <name>whoopsidaisies</name>
        </author>
    </entry>
    
  
</feed>
