【问题标题】:Saved image only shows rectangle created using cv2.rectangle and not the whole image on which rectangle was created保存的图像仅显示使用 cv2.rectangle 创建的矩形,而不是创建矩形的整个图像
【发布时间】:2021-12-10 08:43:04
【问题描述】:

使用此代码时:

 start_point = (centerXList[i] +16,centerYList[i]-14)
 end_point = (centerXList[i]+50,centerYList[i]+24)
 color=(255,0,0)
 x1=cv2.rectangle(x1,start_point,end_point,color)
 imshow(x1)
 plt.show()

imshow的结果是:

但是当使用以下方式保存图像时:

save_img("./Predicted Images/abc.jpeg", x1)

结果是:

https://drive.google.com/file/d/1A4q1buJJk9tBWfstQccgETHe8LDEOtxX/view?usp=sharing

我想保存与 imshow 显示的图像相同的图像。 该怎么做?

提前致谢

【问题讨论】:

  • 您共享的代码可以正常工作。问题是,之前在您的plt 中添加了一张图片。要同时显示图像,请在使用 plt.imshow(img) 之前附加图像

标签: python opencv matplotlib


【解决方案1】:

你试过用这个保存照片吗:

cv2.imwrite('my_saved_image', img)

【讨论】:

  • 我试过了还是不行
【解决方案2】:

我的问题的解决方案是:

save_img("./Predicted Images/abc.jpeg", x1 * 255)

【讨论】:

    猜你喜欢
    • 2020-01-09
    • 1970-01-01
    • 2014-05-13
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2013-04-27
    • 2020-10-18
    相关资源
    最近更新 更多