baseline
BIN
blurred.jpg
Before ![]() (image error) Size: 476 KiB |
BIN
gray.jpg
Before ![]() (image error) Size: 406 KiB |
BIN
images/blurred.jpg
Normal file
After ![]() (image error) Size: 344 KiB |
Before ![]() (image error) Size: 1,023 KiB After ![]() (image error) Size: 1,023 KiB ![]() ![]() |
Before ![]() (image error) Size: 1.1 MiB After ![]() (image error) Size: 1.1 MiB ![]() ![]() |
BIN
images/clean2.jpeg
Normal file
After ![]() (image error) Size: 728 KiB |
Before ![]() (image error) Size: 867 KiB After ![]() (image error) Size: 867 KiB ![]() ![]() |
Before ![]() (image error) Size: 867 KiB After ![]() (image error) Size: 867 KiB ![]() ![]() |
BIN
images/dirty1.jpeg
Normal file
After ![]() (image error) Size: 747 KiB |
BIN
images/dirty2.jpeg
Normal file
After ![]() (image error) Size: 725 KiB |
BIN
images/gray.jpg
Normal file
After ![]() (image error) Size: 294 KiB |
Before ![]() (image error) Size: 5.3 KiB After ![]() (image error) Size: 5.3 KiB ![]() ![]() |
63
main.py
|
@ -1,37 +1,42 @@
|
|||
import cv2
|
||||
import numpy as np
|
||||
from mobile_sam import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor
|
||||
import torch
|
||||
|
||||
model_type = "vit_t"
|
||||
sam_checkpoint = "./models/mobile_sam.pt"
|
||||
|
||||
|
||||
backSub = cv2.createBackgroundSubtractorMOG2(varThreshold=16 )
|
||||
# Load the image
|
||||
image = cv2.imread('dirty.jpeg')
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
refimage = cv2.imread('clean2.jpeg')
|
||||
image = cv2.imread('dirty2.jpeg')
|
||||
|
||||
# Apply Gaussian blur to reduce noise
|
||||
gray = cv2.GaussianBlur(gray, (9, 9), 2)
|
||||
res = cv2.absdiff(refimage, image)
|
||||
|
||||
# Detect circles using the Hough Circles method
|
||||
circles = cv2.HoughCircles(
|
||||
gray,
|
||||
cv2.HOUGH_GRADIENT,
|
||||
dp=1, # Inverse ratio of accumulator resolution to image resolution
|
||||
minDist=20, # Minimum distance between the centers of detected circles
|
||||
param1=50, # Higher threshold for edge detection
|
||||
param2=30, # Accumulator threshold for circle detection
|
||||
minRadius=10, # Minimum radius
|
||||
maxRadius=100 # Maximum radius
|
||||
)
|
||||
res = res.astype(np.uint8)
|
||||
|
||||
if circles is not None:
|
||||
circles = np.uint16(np.around(circles))
|
||||
|
||||
for circle in circles[0, :]:
|
||||
center = (circle[0], circle[1])
|
||||
radius = circle[2]
|
||||
|
||||
# Draw the circle and its center
|
||||
cv2.circle(image, center, radius, (0, 255, 0), 2)
|
||||
cv2.circle(image, center, 2, (0, 0, 255), 3)
|
||||
percentage = (np.count_nonzero(res) * 100)/ res.size
|
||||
|
||||
# Display the result
|
||||
cv2.imshow('Hough Circles', image)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
print(percentage)
|
||||
#cv2.imwrite('/var/www/html/images/blurred.jpg', blurred)
|
||||
|
||||
|
||||
print("Converting to grey")
|
||||
gray_refimage = cv2.cvtColor(refimage, cv2.COLOR_BGR2GRAY)
|
||||
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
|
||||
blurred_refimage = cv2.GaussianBlur(gray_refimage, (9, 9), 2, 2)
|
||||
blurred_image = cv2.GaussianBlur(gray_image, (9, 9), 2, 2)
|
||||
|
||||
#cv2.imwrite('/var/www/html/images/gray.jpg', gray)
|
||||
maska = backSub.apply(blurred_refimage)
|
||||
maskb = backSub.apply(blurred_image)
|
||||
|
||||
cv2.imshow("maskb",maskb)
|
||||
|
||||
cv2.waitKey(0)
|
||||
|
||||
# closing all open windows
|
||||
cv2.destroyAllWindows()
|