img = cv2.imread(fn)\r
else:\r
sz = 4096\r
- print 'generating %dx%d precudural image ...' % (sz, sz)\r
+ print 'generating %dx%d procudural image ...' % (sz, sz)\r
img = np.zeros((sz, sz), np.uint8)\r
- track = np.cumsum(np.random.rand(1000000, 2)-0.5, axis=0)\r
- track = np.int32(track*20 + (sz/2, sz/2))\r
+ track = np.cumsum(np.random.rand(500000, 2)-0.5, axis=0)\r
+ track = np.int32(track*10 + (sz/2, sz/2))\r
cv2.polylines(img, [track], 0, 255, 1, cv.CV_AA)\r
\r
small = img\r
-for i in xrange(4):\r
+for i in xrange(3):\r
small = cv2.pyrDown(small)\r
\r
def onmouse(event, x, y, flags, param):\r
zoom = cv2.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))\r
cv2.imshow('zoom', zoom)\r
\r
-cv2.imshow('small', small)\r
-cv.SetMouseCallback('small', onmouse, None)\r
+cv2.imshow('preview', small)\r
+cv.SetMouseCallback('preview', onmouse, None)\r
cv2.waitKey()\r
import numpy as np\r
from numpy import random\r
-import cv2, cv\r
+import cv2\r
\r
\r
def make_gaussians(cluster_n, img_size):\r
w, u, vt = cv2.SVDecomp(cov)\r
ang = np.rad2deg( np.arctan2(u[1, 0], u[0, 0]) )\r
s1, s2 = np.sqrt(w)*3.0\r
- cv2.ellipse(img, (x, y), (s1, s2), ang, 0, 360, color, 1, cv.CV_AA)\r
+ cv2.ellipse(img, (x, y), (s1, s2), ang, 0, 360, color, 1, cv2.CV_AA)\r
\r
\r
if __name__ == '__main__':\r
samples, responses = a[:,1:], a[:,0]\r
return samples, responses\r
\r
-# TODO move these to cv2\r
-CV_ROW_SAMPLE = 1\r
-CV_VAR_NUMERICAL = 0\r
-CV_VAR_ORDERED = 0\r
-CV_VAR_CATEGORICAL = 1\r
-\r
-\r
class LetterStatModel(object):\r
train_ratio = 0.5\r
def load(self, fn):\r
\r
def train(self, samples, responses):\r
sample_n, var_n = samples.shape\r
- var_types = np.array([CV_VAR_NUMERICAL] * var_n + [CV_VAR_CATEGORICAL], np.uint8)\r
+ var_types = np.array([cv2.CV_VAR_NUMERICAL] * var_n + [cv2.CV_VAR_CATEGORICAL], np.uint8)\r
#CvRTParams(10,10,0,false,15,0,true,4,100,0.01f,CV_TERMCRIT_ITER));\r
params = dict(max_depth=10 )\r
- self.model.train(samples, CV_ROW_SAMPLE, responses, varType = var_types, params = params)\r
+ self.model.train(samples, cv2.CV_ROW_SAMPLE, responses, varType = var_types, params = params)\r
\r
def predict(self, samples):\r
return np.float32( [self.model.predict(s) for s in samples] )\r
sample_n, var_n = samples.shape\r
new_samples = self.unroll_samples(samples)\r
new_responses = self.unroll_responses(responses)\r
- var_types = np.array([CV_VAR_NUMERICAL] * var_n + [CV_VAR_CATEGORICAL, CV_VAR_CATEGORICAL], np.uint8)\r
+ var_types = np.array([cv2.CV_VAR_NUMERICAL] * var_n + [cv2.CV_VAR_CATEGORICAL, cv2.CV_VAR_CATEGORICAL], np.uint8)\r
#CvBoostParams(CvBoost::REAL, 100, 0.95, 5, false, 0 )\r
params = dict(max_depth=5) #, use_surrogates=False)\r
- self.model.train(new_samples, CV_ROW_SAMPLE, new_responses, varType = var_types, params=params)\r
+ self.model.train(new_samples, cv2.CV_ROW_SAMPLE, new_responses, varType = var_types, params=params)\r
\r
def predict(self, samples):\r
new_samples = self.unroll_samples(samples)\r
\r
parser = argparse.ArgumentParser()\r
parser.add_argument('-model', default='rtrees', choices=models.keys())\r
- parser.add_argument('-data', nargs=1, default='letter-recognition.data')\r
+ parser.add_argument('-data', nargs=1, default='../cpp/letter-recognition.data')\r
parser.add_argument('-load', nargs=1)\r
parser.add_argument('-save', nargs=1)\r
args = parser.parse_args()\r