Is there a simple way of changing the origin of image co-ordinate system of OpenCV to bottom left? Using numpy
for example? I am using OpenCv 2.4.12 and Python 2.7.
Related: Numpy flipped coordinate system, but this talks about just display. I want something which I can use consistently in my algorithm.
Update:
def imread(*args, **kwargs):
img = plt.imread(*args, **kwargs)
img = np.flipud(img)
return img
#read reference image using cv2.imread
imref=cv2.imread('D:\\users\\gayathri\\all\\new\\CoilA\\Resized_Results\\coilA_1.png',-1)
cv2.circle(imref, (0,0),30,(0,0,255),2,8,0)
cv2.imshow('imref',imref)
#read the same image using imread function
im=imread('D:\\users\\gayathri\\all\\new\\CoilA\\Resized_Results\\coilA_1.png',-1)
img= im.copy()
cv2.circle(img, (0,0),30,(0,0,255),2,8,0)
cv2.imshow('img',img)
Image read using cv2.imread:
Image flipped using imread function:
As seen the circle is drawn at the origin on upper left corner in both original and flipped image. But the image looks flipped which I do not desire.
Reverse the height (or column) pixels will get the result below.
import numpy as np
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
img = cv2.imread('./imagesStackoverflow/flip_body.png') # read as color image
flip = img[::-1,:,:] # revise height in (height, width, channel)
plt.imshow(img[:,:,::-1]), plt.title('original'), plt.show()
plt.imshow(flip[:,:,::-1]), plt.title('flip vertical'), plt.show()
plt.imshow(img[:,:,::-1]), plt.title('original with inverted y-axis'), plt.gca().invert_yaxis(), plt.show()
plt.imshow(flip[:,:,::-1]), plt.title('flip vertical with inverted y-axis'), plt.gca().invert_yaxis(), plt.show()
Output images:
Above included the one you intended to do?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With