Save Edited Images in OpenCV

In OpenCV, you can use the function cv2.imwrite() to save the modified image.

import cv2

# 读取图片
img = cv2.imread('image.jpg')

# 进行修改操作(例如,绘制矩形框)
cv2.rectangle(img, (100, 100), (200, 200), (0, 255, 0), 2)

# 保存修改后的图片
cv2.imwrite('modified_image.jpg', img)

In the above code, the original image is first read using the cv2.imread() function. Next, modifications are made using drawing functions provided by OpenCV, such as cv2.rectangle(). Finally, the modified image is saved to disk using the cv2.imwrite() function.

Please note that the file path must include the file extension in order for OpenCV to correctly identify the file format and save the image.

bannerAds