问题描述
是否有一种简单的方法可以将OpenCV的图像坐标系的原点更改为左下角?例如使用numpy
?我正在使用OpenCv 2.4.12和Python 2.7.
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.
相关: Numpy翻转坐标系,但这只是显示.我想要可以在算法中持续使用的东西.
Related: Numpy flipped coordinate system, but this talks about just display. I want something which I can use consistently in my algorithm.
更新:
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)
使用cv2.imread读取的图像:
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()
输出图像:
上面包含了您打算做的吗?
Above included the one you intended to do?
这篇关于将图像坐标系的原点更改为左下角,而不是默认的左上角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!