Leonardo Araujo
Leonardo Araujo

Reputation: 105

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. 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)?

Thanks in advance.

BR

Upvotes: 1

Views: 985

Answers (1)

Roy Amoyal
Roy Amoyal

Reputation: 877

You can use cv2.imwrite(filename, img) to save your edited image to your pc.

In your case cv2.imwrite("new_Image", corte_imagem).

Upvotes: 1

Related Questions