I have a cheap Wifi Action camera that i want to use to take a time lapse. I am able to connect to the camera and see a live feed, albeit with a little bit of delay but that doesn't matter to me.
I had a hard time figuring out how to include the code properly here, as i couldn't get it to format correctly. I originally had asked a question on Stackoverflow but after 2 weeks, no one has yet to respond.
https://stackoverflow.com/questions/60776535/how-to-take-time-lapse-pictures-with-opencv-in-python3
I know what my problem is, whenever I have the delay, it also stops the video feed at the time it was paused and then it resumes after. Which it should, since I'm stopping the program right there on its tracks. I have tried looking on the internet for how to delay a program without stopping it, but all i find are inconclusive answers.
I have also found an option on Python3 Called Threading, but that's way out of my skill level right now, even though I have attempted to use it.
Ideally, i want to find a way on having the video feed always open, and only delay the part of the code that tells it to save a picture. And if not, the manual way to take a picture with the space bar still works so it is perfectly doable. But instead of me pressing it, find a way how to emulate a keyboard press, but then i will also need a delay so its pretty inconclusive and redundant to the first option.
I would just like to figure out if I'm heading the right direction, or if I'm just over complicating this. Any information that you can direct me to, or any tips would be really appreciated.
Edit: This is the code that i am currently using(that kinda works)
works)
import cv2
import time time
set_limit = int(input("How many pictures would you like to take? \n: "))
set_time = int(input("What should the interval be in seconds? \n: ")) "))
print("Starting Routine") Routine")
cam = cv2.VideoCapture()
cam.open("rtsp://192.168.1.1") cam.open("rtsp://192.168.1.1")
limit_count = 0
img_counter = 0 0
while(limit_count < set_limit):
ret, frame = cam.read()
cam.read()
if not ret:
break
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
limit_count +=1
time.sleep(set_time)
cam.release()
cv2.destroyAllWindows()
time.sleep(set_time)
cam.release()
cv2.destroyAllWindows()
#time.sleep(set_time)
And this one is the one I'm experimenting with. I was attempting to further delay the program in hopes of renewing the feed a little bit longer in between
import cv2
import time
import datetime
datetime
set_limit = int(input("How many pictures would you like to take? \n: "))
set_time = int(input("What should the interval be in seconds? \n: "))
"))
print("Starting Routine")
Routine")
cam = cv2.VideoCapture()
cam.open("rtsp://192.168.1.1")
cam.open("rtsp://192.168.1.1")
limit_count = 0
img_counter = 0
sec_counter = 0
sec_counter_true = 0
0
while(limit_count < set_limit):
ret, frame = cam.read()
cam.read()
if not ret:
break
if sec_counter >= set_limit:
sec_counter_true = 1
if sec_counter_true == 1:
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name) + " on " + str(datetime.datetime.now()))
img_counter += 1
limit_count +=1
sec_counter_true = 0
sec_counter = 0
sec_counter += 1
print(sec_counter)
time.sleep(set_time)
cam.release()
cv2.destroyAllWindows()
cam.release()
cv2.destroyAllWindows()
Again, I sincerely apologize for the horrible formating.