Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to sort std::vector<cv::rect>?

Trying to sort ROI rectangles from left to right.

auto compare = [](const void* p1, const void* p2) -> int
{
    const int* p1x = &(((const cv::Rect*)p1)->width);
    const int* p2x = &(((const cv::Rect*)p2)->width);
    return (*p2x) - (*p1x);
};
qsort(&vec, vec.size(), sizeof(cv::Rect), compare);

But ->width gives the wrong values.