Skip to content

Instantly share code, notes, and snippets.

@Gotoryoo
Created November 29, 2016 05:31
Show Gist options
  • Save Gotoryoo/d8eb5011099fbf4e4c5aaeb6802532c9 to your computer and use it in GitHub Desktop.
Save Gotoryoo/d8eb5011099fbf4e4c5aaeb6802532c9 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Tue May 19 17:37:46 2015
countingPixel_changekernel_thre.py と同じ内容。
書き込み用テキストが違うだけ。
@author: ryousuke
"""
import cv2
import glob
import os
import itertools
#files = glob.glob("\\\\192.168.0.54\\share\\work\\20140509_mod64pl9twin_betaray\\twin_electron\\20140515x100centerbottom\\*.bmp")
files = glob.glob("..\\*.bmp")
files.sort(key=os.path.getmtime)
fp = open('.//20150519.txt', 'w')
#fpa = open('C:\\Users\\ryousuke\\Desktop\\nakakenn\\img\\2000\\answer.txt', 'w')
#prevx = -999999
#prevy = -999999
kernel = (3 , 5 , 7 )
threth = (2 , 4 , 6 , 8 , 10 )
for file in files:
for c,r in itertools.product(range(len(kernel)), range(len(threth))):
print file
filename = file.split(".")
index = filename[2].split("_")
x = int(index[1])
y = int(index[2])
z = int(index[3])
# if prevx != x or prevy != y:
# fpa.write(str.format("{0} {1}\n",x, y))
# prevx = x
# prevy = y
img = cv2.imread(file,cv2.CV_LOAD_IMAGE_GRAYSCALE)
img_clone = img
#for valthre in [4, 6, 8, 10, 16, 20]:
gau_1 = cv2.GaussianBlur(img_clone , (3,3),-1)
gau_2 = cv2.GaussianBlur(gau_1 , (kernel[c],kernel[c]),-1)
sub = cv2.subtract(gau_2 ,gau_1)
ret,thre = cv2.threshold(sub, threth[r] , 255, cv2.THRESH_BINARY);
count = cv2.countNonZero(thre);
# gau_1.save("C:\\Users\\ryousuke\\Desktop\\nakakenn\\2000hyoumennup\\gau_1\\{0}_{1}.bmp",x,y,"bmp")
# cv2.imwrite("gau_1.bmp",gau_1)
str_disp = str.format("{0} {1} {2} {3} {4} {5}\n",x, y, z, kernel[c],threth[r],count)
print(str_disp)
fp.write(str_disp)
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment