2010-05-11 19:44:00 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import urllib2
|
2011-07-12 14:56:03 +02:00
|
|
|
import cv2.cv as cv
|
2010-05-11 19:44:00 +02:00
|
|
|
|
|
|
|
src=None
|
|
|
|
dst=None
|
|
|
|
src2=None
|
|
|
|
|
|
|
|
def on_mouse(event, x, y, flags, param):
|
|
|
|
|
|
|
|
if not src:
|
|
|
|
return
|
|
|
|
|
|
|
|
if event==cv.CV_EVENT_LBUTTONDOWN:
|
|
|
|
cv.LogPolar(src, dst, (x, y), 40, cv.CV_INTER_LINEAR + cv.CV_WARP_FILL_OUTLIERS)
|
|
|
|
cv.LogPolar(dst, src2, (x, y), 40, cv.CV_INTER_LINEAR + cv.CV_WARP_FILL_OUTLIERS + cv.CV_WARP_INVERSE_MAP)
|
|
|
|
cv.ShowImage("log-polar", dst)
|
|
|
|
cv.ShowImage("inverse log-polar", src2)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-08-07 11:29:43 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
src = cv.LoadImage( sys.argv[1], cv.CV_LOAD_IMAGE_COLOR)
|
|
|
|
else:
|
2012-08-07 11:29:43 +02:00
|
|
|
url = 'http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/c/fruits.jpg'
|
2010-05-11 19:44:00 +02:00
|
|
|
filedata = urllib2.urlopen(url).read()
|
|
|
|
imagefiledata = cv.CreateMatHeader(1, len(filedata), cv.CV_8UC1)
|
|
|
|
cv.SetData(imagefiledata, filedata, len(filedata))
|
|
|
|
src = cv.DecodeImage(imagefiledata, cv.CV_LOAD_IMAGE_COLOR)
|
2012-08-07 11:29:43 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
cv.NamedWindow("original", 1)
|
|
|
|
cv.NamedWindow("log-polar", 1)
|
|
|
|
cv.NamedWindow("inverse log-polar", 1)
|
2012-08-07 11:29:43 +02:00
|
|
|
|
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
dst = cv.CreateImage((256, 256), 8, 3)
|
|
|
|
src2 = cv.CreateImage(cv.GetSize(src), 8, 3)
|
2012-08-07 11:29:43 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
cv.SetMouseCallback("original", on_mouse)
|
|
|
|
on_mouse(cv.CV_EVENT_LBUTTONDOWN, src.width/2, src.height/2, None, None)
|
2012-08-07 11:29:43 +02:00
|
|
|
|
2010-05-11 19:44:00 +02:00
|
|
|
cv.ShowImage("original", src)
|
|
|
|
cv.WaitKey()
|
2012-03-19 00:12:55 +01:00
|
|
|
cv.DestroyAllWindows()
|