Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/python/browse.py
16337 views
1
#!/usr/bin/env python
2
3
'''
4
browse.py
5
=========
6
7
Sample shows how to implement a simple hi resolution image navigation
8
9
Usage
10
-----
11
browse.py [image filename]
12
13
'''
14
15
# Python 2/3 compatibility
16
from __future__ import print_function
17
import sys
18
PY3 = sys.version_info[0] == 3
19
20
if PY3:
21
xrange = range
22
23
import numpy as np
24
import cv2 as cv
25
26
# built-in modules
27
import sys
28
29
if __name__ == '__main__':
30
print('This sample shows how to implement a simple hi resolution image navigation.')
31
print('USAGE: browse.py [image filename]')
32
print()
33
34
if len(sys.argv) > 1:
35
fn = sys.argv[1]
36
print('loading %s ...' % fn)
37
img = cv.imread(fn)
38
if img is None:
39
print('Failed to load fn:', fn)
40
sys.exit(1)
41
42
else:
43
sz = 4096
44
print('generating %dx%d procedural image ...' % (sz, sz))
45
img = np.zeros((sz, sz), np.uint8)
46
track = np.cumsum(np.random.rand(500000, 2)-0.5, axis=0)
47
track = np.int32(track*10 + (sz/2, sz/2))
48
cv.polylines(img, [track], 0, 255, 1, cv.LINE_AA)
49
50
51
small = img
52
for i in xrange(3):
53
small = cv.pyrDown(small)
54
55
def onmouse(event, x, y, flags, param):
56
h, _w = img.shape[:2]
57
h1, _w1 = small.shape[:2]
58
x, y = 1.0*x*h/h1, 1.0*y*h/h1
59
zoom = cv.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
60
cv.imshow('zoom', zoom)
61
62
cv.imshow('preview', small)
63
cv.setMouseCallback('preview', onmouse)
64
cv.waitKey()
65
cv.destroyAllWindows()
66
67