Feret Calculation + subtraction method CV2

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')

New contributor

Agura is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật