Last active
August 29, 2015 13:57
-
-
Save Evgenij-Gr/9659266 to your computer and use it in GitHub Desktop.
Suppose that we have an image on the plane, which borders are parallel to coordinate axis. This procedure does the mapping from plane coordinates to pixels of image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# We lay sides of image parallel to axi of planes | |
# Bigger side of image maps to bigger side of rect | |
# On images we always have X ~ Width, Y ~ Height (it is true for OpenCV) | |
def PlaneToImage(Point, LTCorner, RBCorner, resW, resH): | |
assert(not resW==resH) | |
if (resW > resH): | |
if (abs(LTCorner[0]-RBCorner[0]) > abs(LTCorner[1]-RBCorner[1])): | |
OnImgX, OnImgY = 0, 1 | |
else: | |
OnImgX, OnImgY = 1, 0 | |
else: | |
if (abs(LTCorner[0]-RBCorner[0]) > abs(LTCorner[1]-RBCorner[1])): | |
OnImgX, OnImgY = 1, 0 | |
else: | |
OnImgX, OnImgY = 0, 1 | |
OWidth, OHeight = float(RBCorner[OnImgX]-LTCorner[OnImgX]), float(RBCorner[OnImgY]- LTCorner[OnImgY]) | |
NImgX, NImgY = float(Point[OnImgX]-LTCorner[OnImgX])/OWidth, float(Point[OnImgY]-LTCorner[OnImgY])/OHeight | |
return [int(resW*NImgX), int(resH*NImgY)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment