简体   繁体   English

保存带有注释的 opencv 图像

[英]Save a opencv image with annotations

I think this is a pretty basic question, but I could not find a answer that works.我认为这是一个非常基本的问题,但我找不到有效的答案。

I am writing a code to measure grain size of microstructures using opencv in python and I need to draw circles and lines over an image.我正在编写一个代码来使用 python 中的 opencv 测量微观结构的晶粒尺寸,我需要在图像上绘制圆圈和线条。 Here is the code so far:这是到目前为止的代码:

d_ref = min(dh,dv)
cor_linha = (255,0,0)
esp_linha = 1

l1 = cv2.line(corte_imagem,(int(dh/2+0.9*d_ref/2),int(dv/2-0.9*d_ref/2)),(int(dh/2-0.9*d_ref/2),int(dv/2+0.9*d_ref/2)),cor_linha,esp_linha)
l2 = cv2.line(corte_imagem,(int(dh/2-0.9*d_ref/2),int(dv/2-0.9*d_ref/2)),(int(dh/2+0.9*d_ref/2),int(dv/2+0.9*d_ref/2)),cor_linha,esp_linha)
cv2.circle(corte_imagem,(int(dh/2),int(dv/2)),int(0.9*d_ref/2),cor_linha,esp_linha)
cv2.circle(corte_imagem,(int(dh/2),int(dv/2)),int(0.9*d_ref/3),cor_linha,esp_linha)
cv2.circle(corte_imagem,(int(dh/2),int(dv/2)),int(0.9*d_ref/6),cor_linha,esp_linha)
cv2.imshow('imagem',cv2.cvtColor(corte_imagem, cv2.COLOR_BGR2RGB))

cv2.waitKey(0)
for i in range(8):
    cv2.destoryAllWindows()
    cv2.waitKey(1)

My question is kinda simple: how can I save the image in opencv (or other library) with the annotations (lines and circles)?我的问题有点简单:如何将带有注释(线条和圆圈)的图像保存在 opencv(或其他库)中?

Thanks in advance.提前致谢。

BR BR

You can use cv2.imwrite(filename, img) to save your edited image to your pc.您可以使用cv2.imwrite(filename, img)将编辑后的图像保存到您的电脑。

In your case cv2.imwrite("new_Image", corte_imagem) .在你的情况下cv2.imwrite("new_Image", corte_imagem)

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

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