[メモ] OpenCVサンプル: find_obj.py

- `--feature=brisk`
![Spectacle.n19370.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/75594/2dcbcb4d-a72e-0fdf-f7e0-4e96f6bd68b9.png)



https://qiita.com/mt08/items/e8e8e728cf106ac83218#comment-dbe1ad502bf526744ab5
での確認で、このサンプルを試しました。

# 環境
- Raspberry Pi 3B
- Raspbian: 2019-04-08-raspbian-stretch (デスクトップ環境)
- OpenCV 3.4.6 ([ラズパイ3にOpenCV3/4を簡単に導入](https://qiita.com/mt08/items/e8e8e728cf106ac83218#comment-71008e43257ef38c0d39)より)


# 手順
1. ラズパイ等の準備 ... (省略)
2. サンプルで使用する画像データ取得

    ```shell-session
    pi@raspberrypi:~ $ # Sample Data
    pi@raspberrypi:~ $ wget -q https://github.com/opencv/opencv/raw/master/samples/data/box.png
    pi@raspberrypi:~ $ wget -q https://github.com/opencv/opencv/raw/master/samples/data/box_in_scene.png
    ```

3. `--feature=brisk`にて

	```shell-session
	pi@raspberrypi:~ $ python3 /usr/local/share/OpenCV/samples/python/find_obj.py --feature=brisk box.png box_in_scene.png

	Feature-based image matching sample.

	Note, that you will need the https://github.com/opencv/opencv_contrib repo for SIFT and SURF

	USAGE
	  find_obj.py [--feature=<sift|surf|orb|akaze|brisk>[-flann]] [ <image1> <image2> ]

	  --feature  - Feature to use. Can be sift, surf, orb or brisk. Append '-flann'
				   to feature name to use Flann-based matcher instead bruteforce.

	  Press left mouse button on a feature point to see its matching point.

	using brisk
	img1 - 1662 features, img2 - 2786 features
	matching...
	50 / 52  inliers/matched
	Done
	pi@raspberrypi:~ $
	```
	![Spectacle.n19370.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/75594/2dcbcb4d-a72e-0fdf-f7e0-4e96f6bd68b9.png)



# その他

1. `--feature=sirf`や`--feature=surf`

	[ここで配布しているラズパイ向けパッケージ](https://qiita.com/mt08/items/e8e8e728cf106ac83218#comment-71008e43257ef38c0d39)では、ビルドに含まれていないのでエラーとなります。

	> `(-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'`

	ぐーぐる先生翻訳: 
	> (-213：機能/機能は実装されていません) このアルゴリズムは特許取得済みで、この構成では除外されています。 `OPENCV_ENABLE_NONFREE` CMakeオプションを設定し、関数 'create'でライブラリを再構築します


	```shell-session:実行例
	pi@raspberrypi:~ $ python3 /usr/local/share/OpenCV/samples/python/find_obj.py --feature=sift box.png box_in_scene.png

	Feature-based image matching sample.

	Note, that you will need the https://github.com/opencv/opencv_contrib repo for SIFT and SURF

	USAGE
	  find_obj.py [--feature=<sift|surf|orb|akaze|brisk>[-flann]] [ <image1> <image2> ]

	  --feature  - Feature to use. Can be sift, surf, orb or brisk. Append '-flann'
				   to feature name to use Flann-based matcher instead bruteforce.

	  Press left mouse button on a feature point to see its matching point.

	Traceback (most recent call last):
	  File "/usr/local/share/OpenCV/samples/python/find_obj.py", line 195, in <module>
		main()
	  File "/usr/local/share/OpenCV/samples/python/find_obj.py", line 154, in main
		detector, matcher = init_feature(feature_name)
	  File "/usr/local/share/OpenCV/samples/python/find_obj.py", line 32, in init_feature
		detector = cv.xfeatures2d.SIFT_create()
	cv2.error: OpenCV(3.4.6) /home/pi/opencv_contrib-3.4.6/modules/xfeatures2d/src/sift.cpp:1205: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

	pi@raspberrypi:~ $ 
	```


2. `OPENCV_ENABLE_NONFREE`は今度ためしてみようかと思いますが、公に配布はどうなんでしょう？