Skip to content

Instantly share code, notes, and snippets.

@fhiyo
Created August 21, 2018 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhiyo/73a1814f53204f55faf1484de0ffc792 to your computer and use it in GitHub Desktop.
Save fhiyo/73a1814f53204f55faf1484de0ffc792 to your computer and use it in GitHub Desktop.
opencvによるエッジ抽出のサンプル
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import cv2
import numpy as np
def main():
gray = cv2.imread('lena_std.png', 0) # 入力画像をグレースケールで読み込み
# gray = np.asarray([[0, 0, 1, 1], [0, 0, 1, 7], [1, 0, 8, 8], [0, 1, 8, 9]], dtype=np.uint8)
# カーネル(縦方向の輪郭検出用)
kernel = np.array([[-1, 0, 1],
[-1, 0, 1],
[-1, 0, 1]])
dst1 = cv2.filter2D(gray, -1, kernel)
# print(dst1)
# Output
cv2.imwrite('lena_prewitt.png', dst1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment