title: Count occurrences of repeating elements in a vector<vector<Object>>
body: <p>I have a <code>vector&lt;vector&lt;Rect&gt;&gt;</code>. <code>Rect</code> is a openCV rectangle object. I want to fill up a empty <code>vector&lt;pair&lt;Rect,int&gt;&gt;</code> with all the rectangles that are repeating (1 or more occurrences) in the vector and the number of found occurrences.</p>
  
  <p>My implementation below is not giving me the expected result. Here is what I tried:</p>
  
  <pre><code>vector&lt;vector&lt;Rect&gt;&gt; vec;
  //...fill up vector vec...
  vector&lt;pair&lt;Rect,int&gt;&gt; constantsVec;
  bool found=false;
  
  for(int j=0;j&lt;vec.size()-1;j++){
      vector&lt;Rect&gt; temp1=vec[j];
      vector&lt;Rect&gt; temp2=vec[j+1];
      for(int x=0;x&lt;temp1.size();x++){
          for(int y=0;y&lt;temp2.size();y++){
              if(temp1[x]==temp2[y]){
                  for(int k=0;k&lt;constantsVec.size();k++){
                      if(constantsVec[k].first==temp1[x]){
                          found=true;
                          constantsVec[k]=make_pair(temp1[x],++constantsVec[k].second);
                      }
                  }
                  if(!found){
                      constantsVec.push_back(make_pair(temp1[x],0));
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>In an example with a rectangle that is repeating three times I end up with the correct rectangle in the <code>constantsVec</code> but with 1 as the number of found occurrences instead of 3.</p>
  
  <p>I should add that one element (<code>vector&lt;Rect&gt;</code>) of the <code>vec</code> vector itself has no repeating rectangles but between the elements of the <code>vec</code> vector there can be repeating rectangles. Those are the ones I am trying to find and count.</p>