You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Python的传送带煤炭识别技术咨询:图像降噪与传送带检测

Hey there! Let's tackle your Python-based conveyor belt coal recognition problem step by step—you've already experimented with basic preprocessing like grayscale conversion, contrast boosting, and blurring, so let's level up to solve the noise and detection challenges.

1. Removing Unwanted Pixels (Noise Suppression)

Here are targeted techniques tailored to your conveyor belt scenario:

  • Adaptive Thresholding + Morphological Operations
    Global thresholding often fails with uneven lighting on conveyor belts. Instead, use adaptive thresholding to handle local brightness variations, then clean up small noise with morphological operations. Example code:
    import cv2
    import numpy as np
    
    # Load image as grayscale
    img = cv2.imread("conveyor_photo.jpg", 0)
    # Adaptive Gaussian thresholding (invert to highlight dark coal/conveyor edges)
    adaptive_thresh = cv2.adaptiveThreshold(
        img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2
    )
    # Morphological opening: erode first to remove tiny noise, then dilate to restore shape
    kernel = np.ones((3, 3), np.uint8)
    denoised_img = cv2.morphologyEx(adaptive_thresh, cv2.MORPH_OPEN, kernel)
    
  • Background Subtraction
    If you have a reference image of an empty conveyor, use background difference to isolate foreground (coal + minor noise):
    empty_conveyor = cv2.imread("empty_conveyor.jpg", 0)
    # Calculate absolute difference between current frame and empty conveyor
    diff = cv2.absdiff(img, empty_conveyor)
    # Threshold to filter out small brightness variations
    _, noise_free_diff = cv2.threshold(diff, 30, 255, cv2.THRESH_BINARY)
    
    For continuous video feeds, use cv2.createBackgroundSubtractorMOG2() to dynamically model and update the background.
  • Non-Local Means Denoising
    Unlike Gaussian blur, this preserves edges while removing speckle/gaussian noise. For color images, use the colored variant:
    color_img = cv2.imread("conveyor_photo.jpg")
    denoised_color = cv2.fastNlMeansDenoisingColored(color_img, None, 10, 10, 7, 21)
    

2. Accurately Detecting Conveyor Belt and Coal

Conveyor Belt Boundary Detection

  • Hough Line Transform + Rectangle Fitting
    First extract edges with Canny, then detect lines and filter for conveyor's parallel edges, finally fit a bounding rectangle:
    # Use denoised image from earlier step
    edges = cv2.Canny(denoised_img, 50, 150)
    # Detect lines with probabilistic Hough transform
    lines = cv2.HoughLinesP(
        edges, 1, np.pi / 180, threshold=50, minLineLength=100, maxLineGap=20
    )
    # Filter lines to keep only those matching conveyor's typical slope (near horizontal/vertical)
    conveyor_lines = []
    for line in lines:
        x1, y1, x2, y2 = line[0]
        slope = (y2 - y1) / (x2 - x1) if x2 != x1 else np.inf
        if abs(slope) < 0.1 or abs(slope) > 10:
            conveyor_lines.append(line)
    # Collect all line endpoints and fit minimum area rectangle
    points = []
    for line in conveyor_lines:
        x1, y1, x2, y2 = line[0]
        points.extend([(x1, y1), (x2, y2)])
    points = np.array(points)
    rect = cv2.minAreaRect(points)
    box = cv2.boxPoints(rect)
    box = np.int0(box)
    # Draw conveyor boundary on original image
    cv2.drawContours(color_img, [box], 0, (0, 255, 0), 2)
    
  • Contour Filtering
    If the conveyor is the largest convex shape in the frame, detect all contours, filter by area and convexity, then fit a rectangle:
    contours, _ = cv2.findContours(denoised_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    # Sort contours by area descending
    contours_sorted = sorted(contours, key=cv2.contourArea, reverse=True)
    # Pick the largest convex contour (assumed to be conveyor)
    conveyor_contour = None
    for cnt in contours_sorted:
        if cv2.isContourConvex(cnt):
            conveyor_contour = cnt
            break
    # Fit bounding rectangle
    x, y, w, h = cv2.boundingRect(conveyor_contour)
    cv2.rectangle(color_img, (x, y), (x+w, y+h), (0, 255, 0), 2)
    

Coal Detection

  • Color/Gray Scale Segmentation in ROI
    First define the conveyor's Region of Interest (ROI), then segment coal using its dark color:
    # Use conveyor bounding box from above to get ROI
    roi = color_img[y:y+h, x:x+w]
    # Convert ROI to HSV for better color segmentation
    hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
    # Define HSV range for dark coal (adjust values based on your images)
    lower_coal = np.array([0, 0, 0])
    upper_coal = np.array([180, 255, 80])
    coal_mask = cv2.inRange(hsv_roi, lower_coal, upper_coal)
    # Draw coal mask on original image
    color_img[y:y+h, x:x+w][coal_mask > 0] = (0, 0, 255)
    
  • Lightweight Semantic Segmentation
    For complex scenarios (variable lighting, irregular coal shapes), train a small U-Net model on your labeled data. This will output a pixel-wise mask directly separating coal, conveyor, and background—perfect for volume calculation later.

内容的提问来源于stack exchange,提问作者Illia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:26:31