mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.5 KiB
66 lines
1.5 KiB
12 years ago
|
#!/usr/bin/env python
|
||
12 years ago
|
|
||
12 years ago
|
'''
|
||
|
browse.py
|
||
|
=========
|
||
|
|
||
|
Sample shows how to implement a simple hi resolution image navigation
|
||
|
|
||
|
Usage
|
||
|
-----
|
||
|
browse.py [image filename]
|
||
|
|
||
|
'''
|
||
|
|
||
9 years ago
|
# Python 2/3 compatibility
|
||
|
from __future__ import print_function
|
||
|
import sys
|
||
|
PY3 = sys.version_info[0] == 3
|
||
|
|
||
|
if PY3:
|
||
|
xrange = range
|
||
|
|
||
12 years ago
|
import numpy as np
|
||
|
import cv2
|
||
12 years ago
|
|
||
|
# built-in modules
|
||
12 years ago
|
import sys
|
||
|
|
||
|
if __name__ == '__main__':
|
||
9 years ago
|
print('This sample shows how to implement a simple hi resolution image navigation.')
|
||
|
print('USAGE: browse.py [image filename]')
|
||
|
print()
|
||
12 years ago
|
|
||
|
if len(sys.argv) > 1:
|
||
|
fn = sys.argv[1]
|
||
9 years ago
|
print('loading %s ...' % fn)
|
||
12 years ago
|
img = cv2.imread(fn)
|
||
12 years ago
|
if img is None:
|
||
9 years ago
|
print('Failed to load fn:', fn)
|
||
12 years ago
|
sys.exit(1)
|
||
|
|
||
12 years ago
|
else:
|
||
|
sz = 4096
|
||
9 years ago
|
print('generating %dx%d procedural image ...' % (sz, sz))
|
||
12 years ago
|
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))
|
||
12 years ago
|
cv2.polylines(img, [track], 0, 255, 1, cv2.LINE_AA)
|
||
12 years ago
|
|
||
12 years ago
|
|
||
12 years ago
|
small = img
|
||
|
for i in xrange(3):
|
||
|
small = cv2.pyrDown(small)
|
||
|
|
||
|
def onmouse(event, x, y, flags, param):
|
||
|
h, w = img.shape[:2]
|
||
|
h1, w1 = small.shape[:2]
|
||
|
x, y = 1.0*x*h/h1, 1.0*y*h/h1
|
||
|
zoom = cv2.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
|
||
|
cv2.imshow('zoom', zoom)
|
||
|
|
||
|
cv2.imshow('preview', small)
|
||
|
cv2.setMouseCallback('preview', onmouse)
|
||
|
cv2.waitKey()
|
||
|
cv2.destroyAllWindows()
|