Visual Studioを起動し、新規プロジェクトとして、C#のWPFアプリケーションを作成します。
今回はOCRの結果をJSON形式で受け取るので、JSONを取り扱えるようにするためライブラリを追加します。
まず、メニューバーの「プロジェクト」から「NuGetパッケージの管理」をクリックします。
「参照」をクリックし、検索のテキストボックスに「Json」と入力すると、「System.Runtime.Serialization.Json」が検索結果として表示されます。これを選択して、画面右側の「インストール」ボタンをクリックします。
変更の確認画面が表示されたらOKボタンをクリック。ライセンスへの同意の画面が表示されたら「同意する」をクリックします。
続いて、先ほどインストールしたSystem.Runtime.Serialization.Jsonをプログラム内から使用できるようにするため、メニューバーの「プロジェクト」から「参照の追加」をクリックします。
フレームワークの中にある「System.Runtime.Serialization」にチェックを入れ、OKボタンをクリックします。
MainWindow.xamlのソースについては以下のようになっています(※画面部分のソースコードの解説は本連載の趣旨から外れるので割愛します)。
<Window x:Class="ComputerVisionAPI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ComputerVisionAPI"
mc:Ignorable="d"
Title="OCR (Computer Vision API)" Height="620" Width="525">
<Grid>
<StackPanel Margin="0,20,0,0">
<Button Name="btnSelectnews015_File" Content="画像ファイルを選択" Width="120" Height="30" Click="btnSelectnews015_File_Click"/>
<news015_ Name="imgOCR" Width="300" Height="200"/>
<ComboBox Name="cmbLanguage" Width=" 200" Margin="0,20,0,0">
<ComboBoxItem Content="unk" IsSelected="True" />
<ComboBoxItem Content="ja" />
<ComboBoxItem Content="en" />
</ComboBox>
<Button Name="btnOK" Content="O K" Width="200" Height="50" Margin="0,20,0,0" Click="btnOK_Click"/>
<TextBox Name="tboxResult" Width="500" Height="200" Margin="0,20,0,0"/>
</StackPanel>
</Grid>
</Window>
ボットにCognitive Servicesを組み込んでみる
米IBMがビッグデータ分析基盤サービスを拡充、コグニティブコンピューティングの研究成果も搭載
Google Cloud Vision APIのパブリックβ版が公開Copyright © ITmedia, Inc. All Rights Reserved.