From ecc0929cb0e011db2825e79d7495d7ef7b113e1e Mon Sep 17 00:00:00 2001 From: Tomas Musil Date: Sat, 7 Sep 2013 13:54:23 +0200 Subject: [PATCH 1/1] move modules to subdirectory --- imago | 7 +++++++ imago_pack/__init__.py | 0 camera.py => imago_pack/camera.py | 0 capture.py => imago_pack/capture.py | 0 cs.py => imago_pack/cs.py | 0 filters.py => imago_pack/filters.py | 0 geometry.py => imago_pack/geometry.py | 0 gridf.py => imago_pack/gridf.py | 0 gridf_analyzer.py => imago_pack/gridf_analyzer.py | 0 hough.py => imago_pack/hough.py | 0 im_debug.py => imago_pack/im_debug.py | 0 imago.py => imago_pack/imago.py | 0 intrsc.py => imago_pack/intrsc.py | 24 +++++++++++++---------- k_means.py => imago_pack/k_means.py | 0 lhs.py => imago_pack/lhs.py | 0 linef.py => imago_pack/linef.py | 0 manual.py => imago_pack/manual.py | 0 pso.py => imago_pack/pso.py | 0 sgf.py => imago_pack/sgf.py | 0 timer.py => imago_pack/timer.py | 0 makefile | 2 +- 21 files changed, 22 insertions(+), 11 deletions(-) create mode 100755 imago create mode 100644 imago_pack/__init__.py rename camera.py => imago_pack/camera.py (100%) rename capture.py => imago_pack/capture.py (100%) rename cs.py => imago_pack/cs.py (100%) rename filters.py => imago_pack/filters.py (100%) rename geometry.py => imago_pack/geometry.py (100%) rename gridf.py => imago_pack/gridf.py (100%) rename gridf_analyzer.py => imago_pack/gridf_analyzer.py (100%) rename hough.py => imago_pack/hough.py (100%) rename im_debug.py => imago_pack/im_debug.py (100%) rename imago.py => imago_pack/imago.py (100%) rename intrsc.py => imago_pack/intrsc.py (82%) rename k_means.py => imago_pack/k_means.py (100%) rename lhs.py => imago_pack/lhs.py (100%) rename linef.py => imago_pack/linef.py (100%) rename manual.py => imago_pack/manual.py (100%) rename pso.py => imago_pack/pso.py (100%) rename sgf.py => imago_pack/sgf.py (100%) rename timer.py => imago_pack/timer.py (100%) diff --git a/imago b/imago new file mode 100755 index 0000000..78a81e6 --- /dev/null +++ b/imago @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +"""Go image recognition""" + +from imago_pack import imago + +imago.main() diff --git a/imago_pack/__init__.py b/imago_pack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/camera.py b/imago_pack/camera.py similarity index 100% rename from camera.py rename to imago_pack/camera.py diff --git a/capture.py b/imago_pack/capture.py similarity index 100% rename from capture.py rename to imago_pack/capture.py diff --git a/cs.py b/imago_pack/cs.py similarity index 100% rename from cs.py rename to imago_pack/cs.py diff --git a/filters.py b/imago_pack/filters.py similarity index 100% rename from filters.py rename to imago_pack/filters.py diff --git a/geometry.py b/imago_pack/geometry.py similarity index 100% rename from geometry.py rename to imago_pack/geometry.py diff --git a/gridf.py b/imago_pack/gridf.py similarity index 100% rename from gridf.py rename to imago_pack/gridf.py diff --git a/gridf_analyzer.py b/imago_pack/gridf_analyzer.py similarity index 100% rename from gridf_analyzer.py rename to imago_pack/gridf_analyzer.py diff --git a/hough.py b/imago_pack/hough.py similarity index 100% rename from hough.py rename to imago_pack/hough.py diff --git a/im_debug.py b/imago_pack/im_debug.py similarity index 100% rename from im_debug.py rename to imago_pack/im_debug.py diff --git a/imago.py b/imago_pack/imago.py similarity index 100% rename from imago.py rename to imago_pack/imago.py diff --git a/intrsc.py b/imago_pack/intrsc.py similarity index 82% rename from intrsc.py rename to imago_pack/intrsc.py index 97f9987..445c447 100644 --- a/intrsc.py +++ b/imago_pack/intrsc.py @@ -43,18 +43,18 @@ def board(image, lines, show_all, do_something): board_raw = sum(board_raw, []) ### Show color distribution - luma = [(0.30 * s[0] + 0.59 * s[1] + 0.11 * s[2]) / 255. - for s in board_raw] - saturation = [(max(s) - min(s)) / (255 - abs(max(s) + min(s) - 255)) - for s in board_raw] + luma = [s[0] for s in board_raw] + saturation = [s[1] for s in board_raw] + if show_all: import matplotlib.pyplot as pyplot - pyplot.scatter(luma, saturation, color=[(s[0]/255., s[1]/255., s[2]/255., 1.) - for s in board_raw]) + pyplot.scatter(luma, saturation, + color=[(s[2][0]/255., s[2][1]/255., s[2][2]/255., 1.) + for s in board_raw]) pyplot.show() clusters = k_means.cluster(3, 2,zip(zip(luma, saturation), range(len(luma))), - [[0., 0.], [0.5, 0.25], [1., 0.5]]) + [[0., 0.], [0.5, 0.5], [1., 1.]]) #clusters.sort(key=mean_luma) if show_all: @@ -115,6 +115,10 @@ def stone_color_raw(image, (x, y)): suma.append(image.getpixel((x + i, y + j))) except IndexError: pass - suma = (sum(s[0] for s in suma) / 25., sum(s[1] for s in suma) / 25., - sum(s[2] for s in suma) / 25.) - return suma + luma = sum([0.30 * sum(s[0] for s in suma) / 25., 0.59 * sum(s[1] for s in suma) / 25., + 0.11 * sum(s[2] for s in suma) / 25.]) / 255. + saturation = sum(max(s) - min(s) / float(255. - abs(max(s) + min(s) - 255)) + for s in suma) / (25. * 255.) + color = [sum(s[0] for s in suma) / 25., sum(s[1] for s in suma) / 25., + sum(s[2] for s in suma) / 25.] + return luma, saturation, color diff --git a/k_means.py b/imago_pack/k_means.py similarity index 100% rename from k_means.py rename to imago_pack/k_means.py diff --git a/lhs.py b/imago_pack/lhs.py similarity index 100% rename from lhs.py rename to imago_pack/lhs.py diff --git a/linef.py b/imago_pack/linef.py similarity index 100% rename from linef.py rename to imago_pack/linef.py diff --git a/manual.py b/imago_pack/manual.py similarity index 100% rename from manual.py rename to imago_pack/manual.py diff --git a/pso.py b/imago_pack/pso.py similarity index 100% rename from pso.py rename to imago_pack/pso.py diff --git a/sgf.py b/imago_pack/sgf.py similarity index 100% rename from sgf.py rename to imago_pack/sgf.py diff --git a/timer.py b/imago_pack/timer.py similarity index 100% rename from timer.py rename to imago_pack/timer.py diff --git a/makefile b/makefile index bd149a7..028e827 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ install: pcf.c - gcc -O3 -fPIC -shared -I/usr/include/python2.7/ pcf.c -lpython2.7 -o pcf.so + gcc -O3 -fPIC -shared -I/usr/include/python2.7/ pcf.c -lpython2.7 -o imago_pack/pcf.so clean: rm -f pcf.so -- 2.4.2