いろいろ備忘録

雑記です。

PHPStormでのCakePHPにてDetect PSR-0 namespace rootsが出た時

CakePHP3のブックマークチュートリアルのUserモデルをPHPStormで編集していると

Detect PSR-0 namespace roots: Do you want to configure namespace roots? It can be done automatically or manually at Settings | Directories.

という警告が右下に出た。

\Cake\I18n\Timeなどがどこを指すのか分からないらしい。

 

解決策

編集時に単一のファイルを読み込むのではなく、

/bookmarker
    /bin
    /config
    /logs
    /plugins
    /src
    /tests
    /tmp
    /vendor
    /webroot
    .editorconfig
    .gitignore
    .htaccess
    .travis.yml
    composer.json
    index.php
    phpunit.xml.dist
    README.md

のbookmarkerフォルダを読み込んで、右下に件のダイアログが出たらautomaticallyをクリックすること。

どうしても単一のファイルを読み込みたいときは手動でフォルダを指定しなければならないっぽい。

OpenCVで画像の透明なピクセルの割合を調べる

完全に透明の部分しか渡せません。

Python 2.7.10

 

# -*- coding:utf-8 -*-
import cv2

#アルファチャネルを読み込むためにcv2.IMREAD_UNCHANGEDを渡す
image = cv2.imread('exa.png',cv2.IMREAD_UNCHANGED)
#countNonZeroは1チャネルの画像しか渡せないので、アルファチャネルのみ取り出す
transparentArray = cv2.split(image)[3]
# == transparentArray = image[:,:,3]
imageLen = image.shape[0] * image.shape[1]
#透明はアルファチャンネルが0の部分
alphaLen = imageLen - cv2.countNonZero(transparentArray)

print float(alphaLen) / imageLen

 

今回は必要でないので試していませんが、アルファチャネルが10以下など、完全に透明でない場合は

np.where(np.logical_and(a<=10))

のようにするかもしれません。