I am working on a project of image processing where I am trying to capture a real-time image from my webcam and save it in a specified destination folder. I am doing fine with my job when I am executing my program for the first time. The captured image is being saved in the given destination as expected. But, when I terminate the program and run it again, the new captured image is being overwritten on the previous image and I am loosing my previous images. I want to save all of my images whenever I run the program. Please help me in the issue.
This is my code following:
from tkinter import image_names
import cv2
import os
import matplotlib.pyplot as plt
cap = cv2.VideoCapture(0)
img_counter = 0
for i in range(0, 2):
if cap.isOpened():
ret, frame = cap.read()
print(ret)
print(frame)
else:
ret = False
img1 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
plt.imshow(img1)
plt.title("Camera image 1")
img_names = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_names, frame)
print("Screenshot taken")
img_counter += 1
plt.xticks([])
plt.yticks([])
plt.show()
cap.release()