So, I am working on a project which is basically just passthrough, like the desktop background is your camera (like on vr and stuff). It does work but there is like a one second lag between updating the frames, can someone please help me reduce or even get rid of lag?
passthrough.py:
# importing libraries
import cv2
import time
import os
import ctypes
from wallpaper import set_wallpaper, get_wallpaper
# initialize the camera
cam_port = 0
frame = 0
cam = cv2.VideoCapture(cam_port)
def UpdateFrame():
global frame
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
# saving image in local storage
cv2.imwrite("D:/aaron/Desktop/passthrough/frame_" + str(frame) + ".png", image)
# setting the frames to the desktop background
os.system("D:/aaron/Desktop/passthrough/set_wallpaper_bat.bat " + str(frame))
if frame > 0:
os.remove("D:/aaron/Desktop/passthrough/frame_" + str(frame - 1) + ".png")
frame = frame + 1
# update frames
while True:
UpdateFrame()
set_wallpaper_bat.bat:
cd D:/Aaron/Programs/Python/Python311/Lib/site-packages/wallpaper
win-wallpaper.exe set "D:/aaron/Desktop/passthrough/frame_%1.png"
I tried to use ctypes.windll.user32.SystemParametersInfoW
but it didnt work at all, my desktop background just went pitch black.
2