import cv2

cap = cv2.VideoCapture('http://192.168.163.110/xiao/Hi-Xiao-Ling')
_, frame = cap.read()
old_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    # Compute difference between current frame and the previous frame
    diff_frame = cv2.absdiff(old_gray, gray_frame)
    
    _, diff_frame = cv2.threshold(diff_frame, 25, 255, cv2.THRESH_BINARY)
    
    cv2.imshow("Original", frame)
    cv2.imshow("Object Tracking", diff_frame)
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    
    old_gray = gray_frame.copy()

cap.release()
cv2.destroyAllWindows()