rotate_wrt_img_center()

home > kero > Documentation

kero.ImageProcessing.photoBox.py

def rotate_wrt_img_center(coord, theta, img_width, img_height):
  return coord_out

This function rotates a coordinate with respect to image center.

coord List of integers, coord = [x,y] is the coordinates of the image in pixels. [0,0] is the top-left corner of the image while [width, height] is the bottom-right corner.
theta Float. Angle of rotation in radians.
img_width Integer. Image width in number of pixels.
Img_height Integer. Image height in number of pixels.
return coord_out List of integers, coord_out = [x,y] is the rotated coordinates.

Example Usage 1

import numpy as np
import kero.ImageProcessing.photoBox as kip
import cv2

gg=cv2.imread("boxrotate.png")
img_height, img_width, _ = gg.shape
# print(img_height, img_width)
xmin = 100
ymin = 50
xmax = 110 # 200
ymax = 60# 250
cv2.rectangle(gg, (xmin, ymin), (xmax,ymax),(0,255,0),1)

theta_set = np.linspace(10,330,20)
theta_set = [x*np.pi/180 for x in theta_set]

for theta in theta_set:
	[xmin0, ymin0] = kip.rotate_wrt_img_center([xmin,ymin,xmax,ymax], theta, img_width, img_height)
	print(xmin0,ymin0)
	cv2.rectangle(gg, (xmin0, ymin0), (xmin0+10,ymin0+10),(0,0,255),1)

cv2.imshow("aa",gg)
cv2.waitKey(0)

The above demonstrates how the green rectangle object is rotated wrt origin, which is the center of image.

rotimg

kero version: 0.4.2 and above