diff options
Diffstat (limited to 'bin/3Drotate.py')
| -rwxr-xr-x | bin/3Drotate.py | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/bin/3Drotate.py b/bin/3Drotate.py index a94a7a9..28f1443 100755 --- a/bin/3Drotate.py +++ b/bin/3Drotate.py @@ -156,6 +156,7 @@ foolproof. Use At Your Own Risk. #{{{ defaults # set default value # rotation angles and rotation matrix +auto = None pan = 0 tilt = 0 roll = 0 @@ -220,7 +221,7 @@ def forwardProject(mat, ii, jj): def errMsg(s): - sys.stderr.write("%s\n") + sys.stderr.write("%s\n" % s) sys.exit(1) @@ -246,8 +247,7 @@ def M3inverse(mat): return numpy.linalg.inv(mat) -def call_cmd(s): - cmd = s.split(" ") +def call_cmd(cmd): process = Popen(cmd, stdout=PIPE, stderr=PIPE) out, err = process.communicate() errcode = process.returncode @@ -258,8 +258,8 @@ def call_cmd(s): # get input image size def imagesize(filepath): - width = int(call_cmd("identify -format %w %s" % (filepath))) - height = int(call_cmd("identify -format %h %s" % (filepath))) + width = int(call_cmd(["identify", "-format", "%w", "%s" % (filepath)])) + height = int(call_cmd(["identify", "-format", "%h", "%s" % (filepath)])) return width, height @@ -417,8 +417,9 @@ pid = os.getpid() tmpA = "%s/3Drotate_%s.mpc" % (directory, pid) tmpB = "%s/3Drotate_%s.cache" % (directory, pid) -os.unlink(tmpA, tmpB) -os.unlink(tmpA, tmpB) +for a in [tmpA, tmpB]: + if os.path.exists(a): + os.unlink(a) # test that infile provided if not os.path.exists(infile): @@ -433,7 +434,7 @@ if not pef: pef = 1 # get input image width and height -width, height = imagesize() +width, height = imagesize(infile) maxwidth = width - 1 maxheight = height - 1 @@ -523,7 +524,7 @@ elif zoom <= -1: #}}} dfov = numpy.divide( - numpy.multpily(180, numpy.arctan(36/24)), numpy.pi) + numpy.multiply(180, numpy.arctan(36/24)), numpy.pi) pfact = 1 if pef == 0: # FIXME pfact = numpy.divide(0.01, dfov) @@ -541,7 +542,11 @@ tfov = numpy.divide(sfov, cfov) # calculate focal length in same units as wall (picture) using dfov diag = numpy.sqrt( - numpy.multiply(width, width), numpy.multiply(height, height)) + numpy.add( + numpy.multiply(width, width), + numpy.multiply(height, height) + ) + ) focal = numpy.divide(diag, numpy.multiply(2, tfov)) # calculate forward transform matrix Q @@ -636,6 +641,10 @@ for index in range(0, 4): vmax = vArr[index] delu = numpy.add(numpy.subtract(umax, umin), 1) delv = numpy.add(numpy.subtract(vmax, vmin), 1) +#FIXME ? +offsetu = 0 +offsetv = 0 +#added above if auto == "c": offsetu = numpy.divide(numpy.subtract(width, delu), 2) offsetv = numpy.divide(numpy.subtract(height, delv), 2) @@ -654,37 +663,37 @@ elif auto == "zc": offsetu = 0 offsetv = numpy.divide( numpy.subtract( - height, numpy.divide(numpy.multpily(delv, width), delu)), 2) + height, numpy.divide(numpy.multiply(delv, width), delu)), 2) else: _del = delv offsetu = numpy.divide( numpy.subtract( - width, numpy.divide(numpy.multpily(delu, height), delv)), 2) + width, numpy.divide(numpy.multiply(delu, height), delv)), 2) offsetv = 0 -u1 = numpy.add( - offsetu, - numpy.multpily(numpy.subtract(u1, umin), numpy.divide(width, _del))) -v1 = numpy.add( - offsetv, - numpy.multpily(numpy.subtract(v1, vmin), numpy.divide(height, _del))) -u2 = numpy.add( - offsetu, - numpy.multpily(numpy.subtract(u2, umin), numpy.divide(width, _del))) -v2 = numpy.add( - offsetv, - numpy.multpily(numpy.subtract(v2, vmin), numpy.divide(height, _del))) -u3 = numpy.add( - offsetu, - numpy.multpily(numpy.subtract(u3, umin), numpy.divide(width, _del))) -v3 = numpy.add( - offsetv, - numpy.multpily(numpy.subtract(v3, vmin), numpy.divide(height, _del))) -u4 = numpy.add( - offsetu, - numpy.multpily(numpy.subtract(u4, umin), numpy.divide(width, _del))) -v4 = numpy.add( - offsetv, - numpy.multpily(numpy.subtract(v4, vmin), numpy.divide(height, _del))) + u1 = numpy.add( + offsetu, + numpy.multiply(numpy.subtract(u1, umin), numpy.divide(width, _del))) + v1 = numpy.add( + offsetv, + numpy.multiply(numpy.subtract(v1, vmin), numpy.divide(height, _del))) + u2 = numpy.add( + offsetu, + numpy.multiply(numpy.subtract(u2, umin), numpy.divide(width, _del))) + v2 = numpy.add( + offsetv, + numpy.multiply(numpy.subtract(v2, vmin), numpy.divide(height, _del))) + u3 = numpy.add( + offsetu, + numpy.multiply(numpy.subtract(u3, umin), numpy.divide(width, _del))) + v3 = numpy.add( + offsetv, + numpy.multiply(numpy.subtract(v3, vmin), numpy.divide(height, _del))) + u4 = numpy.add( + offsetu, + numpy.multiply(numpy.subtract(u4, umin), numpy.divide(width, _del))) + v4 = numpy.add( + offsetv, + numpy.multiply(numpy.subtract(v4, vmin), numpy.divide(height, _del))) # # now do the perspective distort if auto == "out": |
