Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added sironuki/.keep
Empty file.
16 changes: 16 additions & 0 deletions sironuki/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 線路白抜きプログラム

## 動作確認済み環境
- Python 3.4.0以上
- 必要なライブラリ
- opencv3
- numpy

## 使い方
```bash
$sinonuki.py hoge.jpg
(何も表示されずに処理が終わる)
$
```
+ コマンドライン第一引数で処理したい画像を指定
+ 処理後の画像はoutput.jpgという名前で作成
37 changes: 37 additions & 0 deletions sironuki/hirata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import cv2
import numpy as np

img = cv2.imread('sample_picture.jpg')

# グレースケール
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# cv2.imwrite('gray.png', gray)

# 二値化
_ ,binary = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY)
# cv2.imwrite('binary.png', binary)

# エッジ抽出
edge = cv2.Canny(img, 50, 150)
# cv2.imwrite('edge.png', edge)

# ネガポジ反転
negaposi = cv2.bitwise_not(edge)
cv2.imwrite('negaposi.png', negaposi)


'''
# エッジ 
import cv2

#Gray Scaleで画像を読み込み
gray_img = cv2.imread('sample_picture.jpg',0)

#Cannyアルゴリズムでエッジ検出
canny_edges = cv2.Canny(gray_img,100,200)

#結果表示
cv2.imshow('sample_picture.jpg',canny_edges)
cv2.waitKey(0)
cv2.destroyAllWindows()
'''
Binary file added sironuki/sample_picture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions sironuki/sironuki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
import cv2
import numpy as np
import sys
# 引数読み込み
args = sys.argv

# 画像の読み込み
# 第一引数:読み込む画像のパス
# 第二引数:カラータイプ -1: RGBA, 0: グレースケール, 1: RGB
img = cv2.imread(args[1], 1)
# 元の画像サイズを取得
orgHeight, orgWidth = img.shape[:2]
# リサイズ時の縮小比率
downsize = (orgHeight//10, orgWidth//10)

# 画像をHSVに変換
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# 取得する色の範囲を指定する
lower_rail = np.array([27, 50, 50])
upper_rail = np.array([120, 255, 255])

# 指定した色に基づいたマスク画像の生成
img_mask = cv2.inRange(hsv, lower_rail, upper_rail)

# フレーム画像とマスク画像の共通の領域を抽出する。
img_color = cv2.bitwise_and(img, img, mask=img_mask)

# リサイズ処理
# 縮小
halfImg = cv2.resize(img_color, downsize)
# 拡大
resizeImg = cv2.resize(halfImg,(orgWidth,orgHeight))

# グレースケール
gray = cv2.cvtColor(resizeImg, cv2.COLOR_BGR2GRAY)

# 二値化
_ ,binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)

# ネガポジ反転
negaposi = cv2.bitwise_not(binary)
cv2.imwrite("output.jpg",negaposi)