view scripts/rescale-homography.py @ 811:429bb43e8278 opencv3

switching the branches to correct names (opencv3.1 is old code previously updated to OpenCV3 and default is now updated to OpenCV 2.4.13
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 10 Jun 2016 15:44:37 -0400
parents 8f8f4375e441
children 56cc8a1f7082
line wrap: on
line source

#! /usr/bin/env python

import sys

import matplotlib.pyplot as plt
import numpy as np
import cv2

import cvutils
import utils

if len(sys.argv) < 4:
   print('Usage: {} homography_filename original_size new_size (size can be width or height)'.format(sys.argv[0]))
   sys.exit()

homography = np.loadtxt(sys.argv[1])

imgPoints = np.array([[10,10],
                      [10,20],
                      [20,20],
                      [20,10]])

wldPoints = cvutils.projectArray(homography, imgPoints.T).T

newSize = float(sys.argv[3])
originalSize = float(sys.argv[2])
imgPoints = imgPoints*newSize/originalSize

newHomography, mask = cv2.findHomography(imgPoints, wldPoints)

np.savetxt(sys.argv[1]+'.new', newHomography)