This commit is contained in:
rattatwinko
2025-05-27 17:20:56 +02:00
parent cceb0d44e8
commit a95b78bd8f
25 changed files with 965 additions and 357 deletions

83
scripts/image_filters.js Normal file
View File

@@ -0,0 +1,83 @@
// Image filter script for JSCA
// This script demonstrates how to apply basic image filters to the camera feed
function applyGrayscale(image) {
var width = image.getWidth();
var height = image.getHeight();
var result = new java.awt.image.BufferedImage(
width, height,
java.awt.image.BufferedImage.TYPE_BYTE_GRAY
);
var g = result.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return result;
}
function applySepia(image) {
var width = image.getWidth();
var height = image.getHeight();
var result = new java.awt.image.BufferedImage(
width, height,
java.awt.image.BufferedImage.TYPE_INT_RGB
);
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
var rgb = image.getRGB(x, y);
var r = (rgb >> 16) & 0xFF;
var g = (rgb >> 8) & 0xFF;
var b = rgb & 0xFF;
var tr = Math.min(255, (r * 0.393 + g * 0.769 + b * 0.189));
var tg = Math.min(255, (r * 0.349 + g * 0.686 + b * 0.168));
var tb = Math.min(255, (r * 0.272 + g * 0.534 + b * 0.131));
result.setRGB(x, y, (tr << 16) | (tg << 8) | tb);
}
}
return result;
}
function applyInvert(image) {
var width = image.getWidth();
var height = image.getHeight();
var result = new java.awt.image.BufferedImage(
width, height,
java.awt.image.BufferedImage.TYPE_INT_RGB
);
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
var rgb = image.getRGB(x, y);
result.setRGB(x, y, ~rgb);
}
}
return result;
}
// Apply the selected filter to the input image
var filterName = "grayscale"; // Change this to "sepia" or "invert" for different effects
var result;
switch (filterName) {
case "grayscale":
result = applyGrayscale(inputImage);
break;
case "sepia":
result = applySepia(inputImage);
break;
case "invert":
result = applyInvert(inputImage);
break;
default:
print("Unknown filter: " + filterName);
result = inputImage;
}
// Return the filtered image
result;

53
scripts/motion_detection.py Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import sys
import cv2
import numpy as np
def detect_motion(image_path):
# Read the input image
frame = cv2.imread(image_path)
if frame is None:
print("Error: Could not read image file")
sys.exit(1)
# Convert to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Apply Gaussian blur to reduce noise
blur = cv2.GaussianBlur(gray, (21, 21), 0)
# Threshold the image to detect significant changes
_, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
# Find contours in the thresholded image
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Filter contours based on area to remove noise
min_area = 500
motion_detected = False
for contour in contours:
if cv2.contourArea(contour) > min_area:
motion_detected = True
# Draw rectangle around motion area
(x, y, w, h) = cv2.boundingRect(contour)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
# Save the output image with motion detection boxes
output_path = image_path.replace('.jpg', '_motion.jpg')
cv2.imwrite(output_path, frame)
# Return result
if motion_detected:
print("Motion detected!")
print(f"Output saved to: {output_path}")
else:
print("No motion detected")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python motion_detection.py <image_path>")
sys.exit(1)
detect_motion(sys.argv[1])