Skip to content

cv.dnn_TextDetectionModel.detectTextRectangles() output is different between OpenCV 4.5.3 and OpenCV 4.5.4 #20930

@UnaNancyOwen

Description

@UnaNancyOwen
System information (version)
  • OpenCV => 4.5.3 and 4.5.4
  • Operating System / Platform => Windows 64 bit
  • Compiler => Python 3.8
Detailed description

The output of cv.dnn_TextDetectionModel.detectTextRectangles() is different between OpenCV 4.5.3 and OpenCV 4.5.4.

In OpenCV 4.5.3, the output is tuple type ((x, y), (widht, height), angle). That is rotated rectangle format of OpenCV and it can be interpreted correctly by cv.boxPoints().

In OpenCV 4.5.4, the output is numpy.ndarray type [x, y, width, height, angle]. It can not be interpreted correctly by cv.boxPoints(). It will occur an error.

Is this a bug? I think it should return tuple type ((x, y), (widht, height), angle).

Steps to reproduce
  1. install opencv-python

    • OpenCV 4.5.3
    pip install opencv-python==4.5.3.56
    
    • OpenCV 4.5.4
    pip install opencv-python==4.5.4.58
    
  2. download model file and test image
    The model file (DB_TD500_resnet50.onnx) for text detection is provided in this tutorial.
    The text image (text_det_test1.png) is provided in test data repository.

  3. run test program

    import cv2 as cv
    
    print(cv.__version__)
    
    # read image
    image = cv.imread("text_det_test1.png")
    
    # create text detection model
    weights = "DB_TD500_resnet50.onnx"
    text_detection_model = cv.dnn_TextDetectionModel_DB(weights)
    
    # set post-processing params
    text_detection_model.setBinaryThreshold(0.3)
    text_detection_model.setPolygonThreshold(0.5)
    text_detection_model.setMaxCandidates(200)
    text_detection_model.setUnclipRatio(2.0)
    
    # set input shape and normalization params
    text_detection_model.setInputScale(1.0 / 255.0)
    text_detection_model.setInputSize(736, 736)
    text_detection_model.setInputMean((122.67891434, 116.66876762, 104.00698793))
    
    # detect text
    rotated_rectangles, _ = text_detection_model.detectTextRectangles(image)
    
    # print points from rotated rectangles
    for rotated_rectangle in rotated_rectangles:
        print(type(rotated_rectangle))
        print(rotated_rectangle)
        points = cv.boxPoints(rotated_rectangle) # error in opencv 4.5.4
        print(points)
  4. output

    • OpenCV 4.5.3
    4.5.3
    <class 'tuple'>
    ((177.50064086914062, 170.92311096191406), (78.48259735107422, 29.635662078857422), -10.561019897460938)
    [[141.63992 192.68217]
    [136.20822 163.54854]
    [213.36136 149.16405]
    [218.79306 178.29768]]
    <class 'tuple'>
    ((226.04806518554688, 118.0884017944336), (202.09889221191406, 52.929649353027344), -12.52880859375)
    [[133.14594  165.84372 ]
    [121.66388  114.174484]
    [318.9502    70.333084]
    [330.43225  122.00232 ]]
    
    • OpenCV 4.5.4
    4.5.4-dev
    <class 'numpy.ndarray'>
    [177.50064  170.92311   78.4826    29.635662 -10.56102 ]
    Traceback (most recent call last):
    File "c:text_detection.py", line 30, in <module>
        points = cv.boxPoints(rotated_rectangle) # error opencv 4.5.4
    cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'boxPoints'
    > Overload resolution failed:
    >  - Can't parse 'box' as RotatedRect. Expected sequence length 3, got 5
    >  - Can't parse 'box' as RotatedRect. Expected sequence length 3, got 5
    
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions