2013-03-06 14:41:02 +08:00
|
|
|
#!/usr/bin/env python
|
2012-11-24 02:57:22 +08:00
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
'''
|
|
|
|
browse.py
|
|
|
|
=========
|
|
|
|
|
|
|
|
Sample shows how to implement a simple hi resolution image navigation
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
browse.py [image filename]
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
import numpy as np
|
2017-12-11 17:55:03 +08:00
|
|
|
import cv2 as cv
|
2013-03-06 14:41:02 +08:00
|
|
|
|
|
|
|
# built-in modules
|
2012-10-17 07:18:30 +08:00
|
|
|
import sys
|
|
|
|
|
2019-03-20 02:03:58 +08:00
|
|
|
def main():
|
2012-10-17 07:18:30 +08:00
|
|
|
if len(sys.argv) > 1:
|
2018-11-14 23:56:21 +08:00
|
|
|
fn = cv.samples.findFile(sys.argv[1])
|
2015-09-14 00:00:22 +08:00
|
|
|
print('loading %s ...' % fn)
|
2017-12-11 17:55:03 +08:00
|
|
|
img = cv.imread(fn)
|
2013-03-06 14:41:02 +08:00
|
|
|
if img is None:
|
2015-09-14 00:00:22 +08:00
|
|
|
print('Failed to load fn:', fn)
|
2013-03-06 14:41:02 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
else:
|
|
|
|
sz = 4096
|
2015-09-14 00:00:22 +08:00
|
|
|
print('generating %dx%d procedural image ...' % (sz, sz))
|
2012-10-17 07:18:30 +08:00
|
|
|
img = np.zeros((sz, sz), np.uint8)
|
|
|
|
track = np.cumsum(np.random.rand(500000, 2)-0.5, axis=0)
|
|
|
|
track = np.int32(track*10 + (sz/2, sz/2))
|
2017-12-11 17:55:03 +08:00
|
|
|
cv.polylines(img, [track], 0, 255, 1, cv.LINE_AA)
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-03-06 14:41:02 +08:00
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
small = img
|
2023-07-13 21:07:10 +08:00
|
|
|
for _i in range(3):
|
2017-12-11 17:55:03 +08:00
|
|
|
small = cv.pyrDown(small)
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
def onmouse(event, x, y, flags, param):
|
2017-08-25 00:45:14 +08:00
|
|
|
h, _w = img.shape[:2]
|
|
|
|
h1, _w1 = small.shape[:2]
|
2012-10-17 07:18:30 +08:00
|
|
|
x, y = 1.0*x*h/h1, 1.0*y*h/h1
|
2017-12-11 17:55:03 +08:00
|
|
|
zoom = cv.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
|
|
|
|
cv.imshow('zoom', zoom)
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2017-12-11 17:55:03 +08:00
|
|
|
cv.imshow('preview', small)
|
|
|
|
cv.setMouseCallback('preview', onmouse)
|
|
|
|
cv.waitKey()
|
2019-03-20 02:03:58 +08:00
|
|
|
print('Done')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print(__doc__)
|
|
|
|
main()
|
2017-12-11 17:55:03 +08:00
|
|
|
cv.destroyAllWindows()
|