Skip to content

Instantly share code, notes, and snippets.

View pythonmasterus's full-sized avatar

pythonmasterus

View GitHub Profile
@pythonmasterus
pythonmasterus / background.py
Created December 19, 2025 09:48
How to implement background subtraction from scratch using only NumPy
import cv2
import numpy as np
# Configuration
BACKGROUND_FILE = 'dublin.jpg'
OBJECT_FILE = 'dublin_edited.jpg'
THRESHOLD_VALUE = 30
MIN_AREA = 500
def main():
@pythonmasterus
pythonmasterus / numpy_detection.py
Created December 19, 2025 09:44
numpy image difference without grayscale
import cv2
import numpy as np
# Configuration
BACKGROUND_FILE = '1.jpg'
OBJECT_FILE = '2.jpg'
MIN_CONTOUR_AREA = 500
THRESHOLD_VALUE = 50
def main():
@pythonmasterus
pythonmasterus / opencv-laplacian-object-extraction.py
Created December 19, 2025 09:21
I am trying to extract a foreground object by subtracting Laplacian edges of a static background image from an edited version of the same image.
import cv2
import numpy as np
# Files must be in the same folder as this script (.py)
background_file = '1.jpg'
object_file = '2.jpg'
def main():
# --- STEP 1: LOAD IMAGES ---
background_img = cv2.imread(background_file)