or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/imutils@0.5.x
tile.json

tessl/pypi-imutils

tessl install tessl/pypi-imutils@0.5.0

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.

Agent Success

Agent success rate when using this tile

91%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.34x

Baseline

Agent success rate without this tile

68%

task.mdevals/scenario-10/

Image Processor with Version Compatibility

A simple image processing module that demonstrates proper handling of OpenCV version differences.

Problem

You need to create an image processing module that works correctly across different OpenCV versions. OpenCV has API breaking changes between versions 2.x, 3.x, and 4.x, particularly in how cv2.findContours() returns results. Your module should handle these differences seamlessly.

Requirements

Create a Python module that provides the following image processing capabilities:

  1. Find and Sort Objects: Implement a function that:

    • Accepts a binary (thresholded) image
    • Finds contours using cv2.findContours() with RETR_EXTERNAL and CHAIN_APPROX_SIMPLE modes
    • Properly extracts contours regardless of OpenCV version (2.x returns 2-tuple, 3.x returns 3-tuple, 4.x returns 2-tuple)
    • Returns contours sorted by area in descending order (largest first)
  2. Get Version Report: Implement a function that returns a dictionary with:

    • A "version" key containing the OpenCV major version as an integer
    • A "supports_modern_features" key that is True if the version is 3.x or higher
    • An "is_latest_major" key that is True if the version is 4.x or higher

Test Cases

  • Given a binary image with 3 objects, find_and_sort_objects returns 3 contours sorted by area descending @test
  • The version report indicates supports_modern_features is True when OpenCV is 3.x or higher @test
  • The version report indicates supports_modern_features is False when OpenCV is 2.x @test
  • The version report indicates is_latest_major is True when OpenCV is 4.x or higher @test

Implementation

@generates

API

def find_and_sort_objects(binary_image):
    """
    Find contours in a binary image and sort by area.

    Args:
        binary_image: A binary (thresholded) image as a numpy array.

    Returns:
        list: List of contours sorted by area in descending order (largest first).
    """

def get_version_report():
    """
    Get information about the OpenCV version.

    Returns:
        dict: Dictionary with keys:
            - "version" (int): Major version number (2, 3, or 4)
            - "supports_modern_features" (bool): True if version 3.x or higher
            - "is_latest_major" (bool): True if version 4.x or higher
    """

Dependencies { .dependencies }

imutils { .dependency }

Provides convenient image processing functions and version compatibility utilities.