Ask Your Question
0

groupRectangles() discrepancy between c++ and python layers

asked 2019-01-31 14:48:37 -0500

sams gravatar image

updated 2019-02-01 07:10:37 -0500

I am trying to convert a call to groupRectangles() from python to c++, and have noticed the output from the python binding does not match the output to the c++ call.

I have edited the below to reflect reproducing the issue on ubuntu 18.04

Library version

I am running opencv on Ubuntu 18.04.

The c++ program is linked against opencv 3.2.0 (as reported by ldd).

The python module reports version 3.2.0

C++ code

I wrote the following program to take a a set of (x1, y1, x2, y2) inputs and pass them to groupRectangles() with a group threshold of 3 and an epsilon of 0.02. For ease of comparison, the output is printed in python's list format.

#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>

// display in python format
std::ostream& operator<<(std::ostream& out, std::vector<cv::Rect>& rectangles)
{
    out << '[';
    for (auto i = 0u; i<rectangles.size(); ++i)
    {
        if (i)
            out << ',';
        out << '[' << rectangles[i].tl().x << ',' << rectangles[i].tl().y << ',' << rectangles[i].br().x << ',' << rectangles[i].br().y << ']';
    }
    return out << ']';
}

// inputs are x1,y1,x2,y2
constexpr const float inputs[][4] = {{547,432,701,639},{557,435,700,640},{560,438,695,641},{560,438,694,640},{88,443,336,663},{83,444,357,671},{83,444,373,676},{87,449,377,676},{87,454,380,677},{76,453,388,680},{72,447,394,683},{80,437,393,683},{101,430,392,678},{547,433,702,641},{555,433,701,645},{558,437,696,647},{556,440,696,644},{84,443,357,664},{73,448,369,665},{74,449,375,664},{81,451,373,664},{85,454,375,666},{81,454,385,672},{74,452,392,676},{77,445,396,679},{91,433,392,680},{547,430,705,644},{553,429,704,649},{555,434,697,649},{552,438,695,649},{85,445,365,661},{69,451,376,662},{69,452,379,663},{76,453,374,663},{80,452,377,666},{79,451,382,671},{74,449,388,673},{77,445,393,673},{90,434,389,674},{546,429,706,643},{553,428,703,647},{554,432,695,649},{553,435,693,654},{81,445,370,663},{68,454,383,664},{67,455,388,664},{72,454,384,667},{77,452,382,669},{71,448,386,671},{66,443,388,672},{73,438,389,671},{92,429,388,673},{545,429,706,642},{553,429,703,643},{553,432,695,647},{553,432,696,658},{79,450,367,664},{72,459,379,663},{71,459,387,665},{75,458,388,667},{75,455,390,666},{65,448,389,668},{63,441,387,669},{73,433,384,672},{100,425,388,675},{549,429,707,648},{550,429,701,652},{554,434,703,662},{79,462,356,665},{73,462,374,665},{74,461,383,666},{73,460,387,667},{69,457,391,664},{60,447,390,668},{63,435,385,673 ...
(more)
edit retag flag offensive close merge delete

Comments

2.4.9 -- even if there's something wrong in the libs/wrappers -- noone cares about an 8 years old, unmaintained branch any more ;(

berak gravatar imageberak ( 2019-02-01 04:24:40 -0500 )edit
1

That is fair. I have replicated the issue on Ubuntu 18.04 with version 3.2.0, and will update the question

sams gravatar imagesams ( 2019-02-01 07:06:52 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-02-07 07:50:53 -0500

sams gravatar image

The issue above is entirely in the python <-> c++ cv::Rect conversion. In python, the list[4] is x, y, height, width, not x1, y1, x2, y2 (as I was led to believed by a bug in the code I was porting).

The code above works correctly if I change the following lines.

While printing:

out << '[' << rectangles[i].tl().x << ',' << rectangles[i].tl().y << ',' << rectangles[i].width << ',' << rectangles[i].height << ']';

While constructing the cv::Rect:

return cv::Rect((int)coord[0], (int)coord[1], (int)coord[2], (int)coord[3]);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-31 14:48:37 -0500

Seen: 39 times

Last updated: Feb 07