<WSH> WScriptに変更する。

ちらっと、WSH (Windows Script Host)を探索中。

VBS(VBScript)で作ったファイルを、ダブルクリックで動かそうとしたら、コマンドプロンプトが起動した。
これを消すのは、既定のスクリプトホストをwscript.exeにしてあげればいいとのこと。

>cscript //h:wscript

の呪文を管理者権限で実施する。

で、下記のコードをhage.vbsで保存して実行。うまくいったなり。

Dim s
s=InputBox("hage")
MsgBox s

<OCR, tesseract, python> 光学的文字認識をやってみた。

諸事情により、画像imageから、テキストを抽出をやってみた。
光学的文字認識Optical Character Recognitionというらしい。

自分の土俵でできるか、、だったが、幸いにmsys2版があった。ラッキー。
で、必要なソフトのインストールからスタート。
このWikiに従う。
Home · tesseract-ocr/tesseract Wiki · GitHub

>pacman -S mingw-w64-{i686,x86_64}-tesseract-ocr
>pacman -S mingw-w64-{i686,x86_64}-tesseract-data-eng

mingw64を使ってこなかったが、ここで、大量にインストールが発生。
まあ、しょうがないので、進める。Go。

次。pythonのパッケージのインストール。

>conda install pillow
>pip install pyocr

で、環境変数設定。

export PATH=$PATH:/mingw64/bin
export TESSDATA_PREFIX=/mingw64/share/tessdata

以上でインストール完了。
では、始めます。

In [7]: import pyocr

In [8]: tool = pyocr.get_available_tools()[0]

In [9]: tool
Out[9]: <module 'pyocr.tesseract' from 'C:\\Anaconda3\\Lib\\site-packages\\pyocr\\tesseract.py'>

In [10]: from PIL import  Image

In [14]: txt = tool.image_to_string(
    ...:     Image.open('capture.PNG'),
    ...:     lang='eng',
    ...:     builder=pyocr.builders.TextBuilder(tesseract_layout=6)
    ...: )

できました。
できたtxtを覗いてみましたが、、、 なんか、行けてない感じ。
単純な英語テキストなのに、完璧には変換できてない。ちと、がっかり感。

少しくぐると、
Google Cloud Vision API というのがあって、こっちはすごいらしい。
次回試してみるかな。。。

github.com

qiita.com

<ATOM> Proxy越しのアップデート、その2

Proxy越しのアップデート、その2。
久々に、アトムさんatomSetting開いて、アップデートUpdateしようとしたらこけた。
どうもプロキシさんが変わったので、設定しなおした。
ちと、はまったので、メモ。

その1...
atomさんの設定ファイルは下記にある。

C:\\Users\\hage\\.atom\\.apmrc

その2...
設定ファイルの中身が正しく反映されているかは、下記コマンドで確認できる。

C:\Users\hage\.atom>apm config ls
; cli configs
globalconfig = "C:\\Users\\hage\\.atom\\.apm\\.apmrc"
user-agent = "npm/3.10.10 node/v6.9.5 win32 ia32"
userconfig = "C:\\Users\\hage\\.atom\\.apmrc"

; environment configs
node-gyp = "C:\\Users\\hage\\AppData\\Local\\atom\\app-1.23.3\\resources\\app\\apm\\bin\\\\..\\node_modules\\node-gyp\\bin\\node-gyp.js"

; userconfig C:\Users\hage\.atom\.apmrc
http-proxy = "http://hagehage.hohoho.com:80"
https-proxy = "http://hagehage.hohoho.com:80/"
strict-ssl = false

; globalconfig C:\Users\hage\.atom\.apm\.apmrc
cache = "C:\\Users\\hage\\.atom\\.apm"
progress = false

; node bin location = C:\Users\hage\AppData\Local\atom\app-1.23.3\resources\app\apm\bin\node.exe
; cwd = C:\Users\hage\.atom
; HOME = C:\Users\hage
; "npm config ls -l" to show all defaults.

その3...
https-proxyの設定のところは、プロキシの設定値を、httpsでなくて、httpsを抜かないといけん。
これが一番はまった。
sつけたままだと、アップデートのところで、次のエラーが発生した。

tunneling socket could not be established, cause=socket hang up

この人に助けられた。ありがとうです。
note.nkmk.me

昔の記事っす。
nekoyukimmm.hatenablog.com

<pandas, Python> 条件にあった行を削除する。

条件conditionにあった行Rowを削除dropする。

まずは、お見本データフレームDataFrame作成。

In [54]: data='''
    ...: 1 2 3 4 5
    ...: a b c d e
    ...: f g h i j
    ...: k l m n o
    ...: '''

In [55]: df = pd.read_table(io.StringIO(data), sep=' ')

In [56]: df
Out[56]: 
   1  2  3  4  5
0  a  b  c  d  e
1  f  g  h  i  j
2  k  l  m  n  o

で、行のドロップ。
インデックスindexで指定すればよし。

In [58]: df.drop(1)
Out[58]: 
   1  2  3  4  5
0  a  b  c  d  e
2  k  l  m  n  o

In [59]: df.drop([1])
Out[59]: 
   1  2  3  4  5
0  a  b  c  d  e
2  k  l  m  n  o

で、列columnの場合はaxis=1を指定。

In [61]: df.drop(['1'], axis=1)
Out[61]: 
   2  3  4  5
0  b  c  d  e
1  g  h  i  j
2  l  m  n  o

あとは、条件にあった行を見つける。

In [65]: df[['1', '3']].apply(lambda x: True if x[0] == 'f' and x[1] == 'h' else False, axis=1)
Out[65]: 
0    False
1     True
2    False
dtype: bool

In [66]: j = df[['1', '3']].apply(lambda x: True if x[0] == 'f' and x[1] == 'h' else False, axis=1)

In [67]: j
Out[67]: 
0    False
1     True
2    False
dtype: bool

で、True/Falseのリストをデータフレームに突っ込めばオッケー。

In [68]: df[j]
Out[68]: 
   1  2  3  4  5
1  f  g  h  i  j

が、、、こんな難しいことせんでも下記でよかった。。。

In [78]: df[(df['1'] == 'f') & (df['3'] == 'h')]
Out[78]: 
   1  2  3  4  5
1  f  g  h  i  j