简体   繁体   English

plt.imshow() 绘制的图像是倒置的,而 cv2_imshow() 绘制的图像很好,我怎么知道我的 neural.net 得到了什么?

[英]Image plotted by plt.imshow() is inverted while same image by cv2_imshow() is fine, how do I know what my neural net gets?

Here is my snippet for both of them这是我对他们两个的片段

from google.colab.patches import cv2_imshow 
import cv2 
pt = '/content/content/DATA/testing_data/1/126056495_AO_BIZ-0000320943-Process_IP_Cheque_page-0001.jpg' #@param
img = cv2.imread(pt) 
cv2_imshow(img) 

and here is the other one这是另一个

import matplotlib.image as mpimg

pt = '/content/content/DATA/testing_data/1/126056495_AO_BIZ-0000320943-Process_IP_Cheque_page-0001.jpg'
image = mpimg.imread(pt)
plt.imshow(image)

Now, the image in second case is inverted and image on my system is upright现在,第二种情况下的图像是倒置的,而我系统上的图像是直立的

What I am mostly afraid of is, if my ML model is consuming inverted image, that is probably messing with my accuracy.我最担心的是,如果我的 ML model 正在消耗倒像,那可能会影响我的准确性。 What could possibly be the reason to It and how do I fix it它可能是什么原因以及我该如何解决

(ps: I cannot share the pictures unfortunately, as they are confidential ) (Run on google colab) All the help is appreciated (ps:不幸的是,我不能分享这些图片,因为它们是机密的)(在 google colab 上运行)感谢所有帮助

Your picture is upside-down when you use one method for reading, and upright when you use the other method?你用一种方法看图是倒着的,用另一种方法看图是正的?

You use two different methods to read the image file:您使用两种不同的方法来读取图像文件:

  • OpenCV cv.imread() OpenCV cv.imread()
  • Mediapipe mpimg.imread()媒体mpimg.imread()

They behave differently.他们的行为不同。 OpenCV's imread() respects file metadata and rotates the image as instructed. OpenCV 的imread()尊重文件元数据并按照指示旋转图像。 Mediapipe's function does not. Mediapipe 的 function 没有。

Solution: Stick to OpenCV's imread() .解决方案:坚持使用 OpenCV 的imread() Don't use Mediapipe's function.不要使用 Mediapipe 的 function。


The issue is not with matplotlib .问题在于 matplotlib When plt.imshow() is called, it presents the image with an origin in the top left corner, ie the Y-axis grows downward.plt.imshow()时,它会显示原点在左上角的图像,即 Y 轴向下增长。 That corresponds to how cv.imshow() behaves.这对应于cv.imshow()的行为方式。

If your plot does have an Y-axis growing upwards, causing the image to stand upside-down, then you must have set this plot up in specific ways that aren't presented in your question.如果您的 plot确实有一个向上增长的 Y 轴,导致图像颠倒,那么您必须以问题中未出现的特定方式设置此 plot。

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

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