Reputation:
I have a python script which looks like this:
import cv2
if __name__ == "__main__":
predict_filename = "prediction.jpg"
predict_cv2 = cv2.imread(prediction_filename)
cv2.rectangle(predict_cv2, (50,50), (100,100), (225,0,225), 6)
print("changing ", predict_filename , " done")
I am trying to draw boxes to display object detection results later on, but until now I am struggling to draw boxes onto pictures in general.
prediction.jpg
exists in the same file as the script, but will stay the same when running the code. Where is my mistake?
Upvotes: 0
Views: 1083
Reputation: 191
All you need to do is use the cv2.imwrite statement to get the desired result, before the draw rectangle command.
cv2.imwrite("File_name.jpg", predict_cv2)
Upvotes: 0
Reputation: 36
you are drawing the rectangle on the numpy array of predict_cv2,if u want to save this image u need to use the command cv2.imwrite("file name", array to save)
import cv2
if __name__ == "__main__":
predict_filename = "prediction.jpg"
predict_cv2 = cv2.imread(prediction_filename)
cv2.rectangle(predict_cv2, (50,50), (100,100), (225,0,225), 6)
cv2.imwrite("ImageWithRectangle.jpg", predict_cv2)
print("changing ", predict_filename , " done")
this should save the image with rectangle on the project folder.
Upvotes: 1