CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-imutils

A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, displaying Matplotlib images, sorting contours, detecting edges, and much more easier with OpenCV and both Python 2.7 and Python 3.

91

1.33x
Overview
Eval results
Files

task.mdevals/scenario-6/

Object Counter

Build a tool that detects, sorts, and labels objects in an image for systematic counting and visualization.

Requirements

Your implementation should:

  1. Load an image containing multiple objects (coins, shapes, etc.)
  2. Detect all distinct objects in the image using appropriate preprocessing and contour detection
  3. Sort the detected objects spatially from left to right
  4. Draw each object's boundary on the image
  5. Label each object with a sequential number starting from 1
  6. Display or save the final annotated image

The tool should handle grayscale conversion, noise reduction, and thresholding to ensure reliable object detection. Objects should be numbered systematically based on their left-to-right position.

@generates

API

def count_and_label_objects(image_path: str, output_path: str = None) -> int:
    """
    Detects, sorts, and labels objects in an image.

    Args:
        image_path: Path to the input image
        output_path: Optional path to save the annotated image

    Returns:
        The total count of detected objects
    """
    pass

Test Cases

  • When given an image with 5 coins arranged horizontally, the function detects all 5 coins and labels them 1 through 5 from left to right @test
  • When given an image with overlapping shapes, the function correctly separates and counts only distinct contours @test
  • The function returns the correct count matching the number of labeled objects @test

Dependencies { .dependencies }

OpenCV { .dependency }

Provides image processing and computer vision capabilities.

NumPy { .dependency }

Provides array manipulation support.

imutils { .dependency }

Provides convenience functions for image processing tasks.

Install with Tessl CLI

npx tessl i tessl/pypi-imutils

tile.json