I’m facing some challenges with the accuracy of my current results. Specifically, the Feret detection is proving to be inaccurate due to issues with object detection, primarily caused by transparency in the images. Currently, I’m relying on the subtraction method provided by OpenCV (CV2) for background subtraction.
Given the nature of my images, which include transparent or semi-transparent objects, the traditional background subtraction technique may not adequately segment the foreground from the background. This could lead to misleading Feret diameters and other measurements.
I’m exploring potential solutions to enhance the accuracy of my results. One approach I’m considering involves refining the background subtraction process to better handle transparency. Additionally, I’m open to exploring alternative methods or algorithms that are more robust in scenarios involving transparent objects.
If you have any insights, suggestions, or recommendations on how to improve the accuracy of Feret detection in the presence of transparency, I would greatly appreciate your expertise and guidance.
Thank you for your assistance.
Detailed output here(image)
here is the code:
import cv2 as cv
import os
import numpy as np
import matplotlib.pyplot as plt
import feret # Assuming feret module is imported correctly
# Function to display images in Jupyter
def display_image(image, title='Image'):
plt.figure(figsize=(10, 10))
plt.imshow(cv.cvtColor(image, cv.COLOR_BGR2RGB))
plt.title(title)
plt.axis('off')
plt.show()
# Path to the folder containing images and the background image
image_folder = 'Camera2/front'
background_image_path = 'Main.jpeg'
# Load the background image
background_image = cv.imread(background_image_path, cv.IMREAD_COLOR)
if background_image is None:
print(f"Unable to load background image: {background_image_path}")
exit(1)
# Iterate through each file in the folder
for filename in os.listdir(image_folder):
if filename.endswith('.jpeg') and filename != 'Main.jpeg':
image_path = os.path.join(image_folder, filename)
# Load the current image
image = cv.imread(image_path, cv.IMREAD_COLOR)
if image is None:
print(f"Unable to load image: {image_path}")
continue
# Perform background subtraction
fgMask = cv.absdiff(background_image, image)
# Convert to grayscale for thresholding (if needed)
fgMask_gray = cv.cvtColor(fgMask, cv.COLOR_BGR2GRAY)
# Apply a threshold to get the binary image
_, fgMask_binary = cv.threshold(fgMask_gray, 50, 255, cv.THRESH_BINARY)
# Display the original image and the foreground mask
display_image(image, title='Original Image')
display_image(fgMask_binary, title='Foreground Mask')
# Plot Feret diameters on the preprocessed image
feret.plot(fgMask_binary)
# Calculate Feret diameters and angles
maxf_length, minf_length, minf_angle, maxf_angle = feret.all(fgMask_binary)
# Print the results for the current image
print(f"Filename: {filename}, Max Feret Length: {maxf_length}, Min Feret Length: {minf_length}")
# Pause to control the display in the notebook
input("Press Enter to continue...")
# Clean up
plt.close('all')
Agura is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.