How to use C++ to achieve the following python functionality(detection merge)

import numpy as np
import cv2

src = cv2.imread('A.jpg')
cv2.imshow('src', src)

split_res = src.copy()
merge_res = src.copy()

start = cv2.getTickCount()
hsvImg = cv2.cvtColor(src,cv2.COLOR_BGR2HSV)
H,S,V = cv2.split(hsvImg)
ret, thresImg= cv2.threshold(S, 138, 255, cv2.THRESH_BINARY)
cv2.imshow('threshold', thresImg)
blurImg = cv2.medianBlur(thresImg,5)
cv2.imshow('blur', blurImg)
 
contours,hierarchy = cv2.findContours(blurImg, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

merge_list = []
for cnt in contours:
  rect = cv2.minAreaRect(cnt)
  
  box = cv2.boxPoints(rect)
  box = np.int0(box)
  split_res = cv2.drawContours(split_res,[box],0,(0,0,255),2)
  merge_list.append(cnt)
cv2.imshow('split_res', split_res)
cv2.imwrite('split_res.jpg', split_res)

contours_merge = np.vstack([merge_list[0],merge_list[1]])
for i in range(2, len(merge_list)):
  contours_merge = np.vstack([contours_merge,merge_list[i]])

rect2 = cv2.minAreaRect(contours_merge)
box2 = cv2.boxPoints(rect2)
box2 = np.int0(box2)
merge_res = cv2.drawContours(merge_res,[box2],0,(0,255,0),2)
cv2.imshow('merge_res', merge_res)
cv2.imwrite('merge_res.jpg', merge_res)

end = cv2.getTickCount()

use_time = (end - start) / cv2.getTickFrequency()
print('use-time: %.3fs' % use_time)

cv2.waitKey(0)
cv2.destroyAllWindows()
print ('finish')

if the problem is finding a np.vstack() replacement, std::vector has a push_back member for this, as in:


vector<vector<Point>> all_contours = ...
vector<Point> new_contour = ...

all_contours.push_back(new_contour);