pythonでOpenCV使ってレシートとかメモとかその他諸々の四角い領域を発見、そいつを切り抜く。そんな感じのプログラムを書きました。 書きましたって言ってもだいぶ前に書いたやつなのですが、リクエストがあったので公開します。 とりあえずソースコード。大雑把な解説は下に。 Copy #!/usr/bin/python3 import cv2 import numpy def transform_by4(img, points): """ 4点を指定してトリミングする。 """ points = sorted(points, key=lambda x:x[1]) # yが小さいもの順に並び替え。 top = sorted(points[:2], key=lambda x:x[0]) # 前半二つは四角形の上。xで並び替えると左右も分かる。 bottom = sorted(points[2:]
ちょっとやってみたい事があるので,その準備として画像中の矩形検出処理を書いてみました.処理手順は単純に 画像を2値化 輪郭線検出 輪郭線を近似して,四角形になっているか判定 のような感じです. 四角形かどうかの判定は4点かつ,面積が一定以上かどうかで判定しています. 追加で凸形になっているかを調べるともっといいかもしれません. 緑が検出された輪郭線.青がその中で矩形っぽいもの. 2014/03/20 ソースちょっと修正 /*************************** * 矩形検出 * @author : tetro ***************************/ #include <vector> #include <sstream> #include <iostream> #include <opencv2/opencv.hpp> /*****************
In this tutorial, you will learn Simple thresholding, Adaptive thresholding, Otsu’s thresholding etc. You will learn these functions : cv2.threshold, cv2.adaptiveThreshold etc. Simple Thresholding¶ Here, the matter is straight forward. If pixel value is greater than a threshold value, it is assigned one value (may be white), else it is assigned another value (may be black). The function used is cv
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く