1

I have two rectangle vectors

std::vector<cv::Rect>faces;
std::vector<cv::Rect>windows;

I need to concatenate windows with faces...for that I wrote the code as

 int fsize=faces.size();
    for(int i=0;i<windows.size();i++)
    {
        faces[fsize]=windows[i];
        fsize++;
    }

But I thk this code is creating segmentation faults...anybody know anything betr..or any built in functions??

ranger
  • 496
  • 2
  • 6
  • 18

2 Answers2

3

Use insert:

faces.insert(faces.end(), windows.begin(), windows.end());

or to move the contents:

faces.insert(faces.end(), std::make_move_iterator(windows.begin()), 
                          std::make_move_iterator(windows.end()));
Jesse Good
  • 50,901
  • 14
  • 124
  • 166
2

You are replacing faces with windows and if windows have more elements than faces you access out of boundary of faces.

If you really mean Concatenating instead of replacing:

faces.reserve(faces.size() + windows.size());
faces.insert(faces.end(), windows.begin(), windows.end());
billz
  • 44,644
  • 9
  • 83
  • 100