Skip to content

Instantly share code, notes, and snippets.

@Gotoryoo
Last active December 2, 2016 13:32
Show Gist options
  • Save Gotoryoo/d48b3a33db48e918cb9b to your computer and use it in GitHub Desktop.
Save Gotoryoo/d48b3a33db48e918cb9b to your computer and use it in GitHub Desktop.
作成したコードをGitHubに送信するtestとしてmytoool.pyをあげる。
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 19 14:59:47 2015
@author: ryousuke
"""
import cv2
import numpy as np
def funcDouble(x):
return 2*x
def funcTriple(x):
return 3*x
def funcPower(x):
return x*x
def funcContrust(img):
min = 0
max = 255
img_dst = cv2.normalize(img, alpha=min, beta=max, norm_type=cv2.NORM_MINMAX)
return img_dst
def funcGaussian(img,kernel = 51):
gau_1 = cv2.GaussianBlur(funcContrust(img) , (3,3),-1)
gau_2 = cv2.GaussianBlur(gau_1 , (kernel,kernel),-1)
sub = cv2.subtract(gau_2 ,gau_1)
return sub
def funcThreshold(img,kernel = 51,threshold = 100 ,max_brt = 10):
ret,thre = cv2.threshold(funcGaussian(img,kernel), threshold , max_brt, cv2.THRESH_BINARY)
return thre
def funcCountNonZero(img,kernel,threshold):
count = cv2.countNonZero(funcThreshold(img,kernel,threshold))
return count
def funcRotation(img,angle,center_x = 256,center_y = 220,scale = 1.0):
##ここから下は、アフィン変換によって画像を回転させる関数である。
center = tuple(np.array([center_x, center_y]))
# 画像サイズの取得(横, 縦)
size = tuple(np.array([img.shape[1], img.shape[0]]))
# 回転させたい角度
# ラジアンではなく角度(°)
# 回転変換行列の算出
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)
# アフィン変換
img_rot = cv2.warpAffine(img, rotation_matrix, size, flags=cv2.INTER_CUBIC)
return img_rot
if __name__ == '__main__':
print "testcode for funcDouble"
assert funcDouble(0) == 0
assert funcDouble(-5) == -10
assert funcDouble(3.0) == 6.0
assert funcDouble(200.0) == 400.0
print "test OK"
print "testcode for funcTriple"
assert funcTriple(0) == 0
assert funcTriple(-5) == -15
assert funcTriple(3.0) == 9.0
assert funcTriple(200.0) == 600.0
print "test OK"
print "testcode for funcPower"
assert funcPower(0) == 0
assert funcPower(-5) == 25
assert funcPower(3.0) == 9.0
assert funcPower(20.0) == 400.0
print "test OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment