简体   繁体   English

如何在python中使用opencv在图像上显示轴

[英]How to display axes on an image with opencv in python

Is there a way to show the row and column axes when displaying an image with cv2.imshow()? 使用cv2.imshow()显示图像时,是否可以显示行轴和列轴? I am using the python bindings for opencv3.0 我正在为opencv3.0使用python绑定

Not that I am aware of. 不是我知道的。

However, since you are using Python you are not constrained to use the rudimentary plotting capabilities of OpenCV HighGUI. 但是,由于您使用的是Python,因此您不必使用OpenCV HighGUI的基本绘图功能。

Instead, you can use the much more competent matplotlib library (or any of the other available Python plotting libraries). 相反,您可以使用功能更matplotlib库(或任何其他可用的Python绘图库)。

To plot an image, including a default axis you do 要绘制图像(包括默认轴),请执行以下操作

import matplotlib.pyplot as plt
plt.imshow(image, interpolation='none') # Plot the image, turn off interpolation
plt.show() # Show the image window

I'm not sure I fully understand the question due to lack of info. 由于缺乏信息,我不确定我是否完全理解该问题。

However you can use OpenCV's draw line function to draw a line from the example points (10,10) to (10,190), and another from (10,190) to (190,190) 但是,您可以使用OpenCV的画线功能从示例点(10,10)到(10,190)画一条线,再从(10,190)到(190,190)的点画一条线。

On an example image that is 200X200 pixels in size, this will draw a line down the left hand side of the image, and a line along the bottom. 在尺寸为200X200像素的示例图像上,这将在图像的左下方绘制一条线,并在底部绘制一条线。 You can then plot numbers or whatever you want along this line at increments of X-pixels. 然后,您可以沿这条线以X像素的增量绘制数字或任何您想要的图形。

Drawing text/numbers to an image is similar to drawing a line. 在图像上绘制文本/数字类似于绘制线条。

Once you have drawn the image, show with the usual image.imshow(). 绘制图像后,使用通常的image.imshow()进行显示。

See OpenCV's drawing documentation here: 请在此处查看OpenCV的图纸文档:

http://docs.opencv.org/modules/core/doc/drawing_functions.html http://docs.opencv.org/modules/core/doc/drawing_functions.html

And an example to get you going can be found here: 在这里可以找到帮助您前进的示例:

http://opencvexamples.blogspot.com/2013/10/basic-drawing-examples.html#.VMj-bUesXuM http://opencvexamples.blogspot.com/2013/10/basic-drawing-examples.html#.VMj-bUesXuM

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM