Is there any way to get these both to run simultaneously? Like making the video stream run in the bg or something.
Video Stream:
def gen(camera):
while True:
frame = camera.get_frame()
yield frame
@eel.expose
def video_feed():
x = VideoCamera()
y = gen(x)
for each in y:
# Convert bytes to base64 encoded str, as we can only pass json to frontend
blob = base64.b64encode(each)
blob = blob.decode("utf-8")
eel.updateImageSrc(blob, 'output')
Frame Capture:
@eel.expose
def CamDetection():
cap = cv2.VideoCapture(1)
img_counter = 0
if True:
ret, frame = cap.read()
if not (cap.isOpened()):
print("failed to grab frame")
# break
# cv2.imshow("test", frame)
# k = cv2.waitKey(1)
# if k%256 == 27:
# # ESC pressed
# print("Escape hit, closing...")
# break
# if k%256 == 32:
# # SPACE pressed
img_name = "SKH_frame.png".format(img_counter)
path = 'F:\Tensorflow\yolov5\webcamimage'
cv2.imwrite(os.path.join(path, img_name), frame)
print("{} written!".format(img_name))
img_counter += 1
cap.release()