python cv2 sample: hi-res image browse
authorAlexander Mordvintsev <no@email>
Mon, 6 Jun 2011 03:31:45 +0000 (03:31 +0000)
committerAlexander Mordvintsev <no@email>
Mon, 6 Jun 2011 03:31:45 +0000 (03:31 +0000)
samples/python2/browse.py [new file with mode: 0644]

diff --git a/samples/python2/browse.py b/samples/python2/browse.py
new file mode 100644 (file)
index 0000000..ed2353f
--- /dev/null
@@ -0,0 +1,38 @@
+'''\r
+browse.py shows how to implement a simple hi resolution image navigation\r
+'''\r
+\r
+import numpy as np\r
+import cv2, cv\r
+import sys\r
+\r
+print 'This sample shows how to implement a simple hi resolution image navigation.'\r
+print 'USAGE: browse.py [image filename]'\r
+print \r
+\r
+if len(sys.argv) > 1:\r
+    fn = sys.argv[1]\r
+    print 'loading %s ...' % fn\r
+    img = cv2.imread(fn)\r
+else:\r
+    sz = 4096\r
+    print 'generating %dx%d precudural 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
+    cv2.polylines(img, [track], 0, 255, 1, cv.CV_AA)\r
+\r
+small = img\r
+for i in xrange(4):\r
+    small = cv2.pyrDown(small)\r
+\r
+def onmouse(event, x, y, flags, param):\r
+    h, w = img.shape[:2]\r
+    h1, w1 = small.shape[:2]\r
+    x, y = 1.0*x*h/h1, 1.0*y*h/h1\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.waitKey()\r