from collections import defaultdict
default_criteria_type = cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER
criteria = kwargs.get('criteria', (default_criteria_type, 10, 1.0))
flags = kwargs.get('flags', cv2.KMEANS_RANDOM_CENTERS)
attempts = kwargs.get('attempts', 10)
angles = np.array([line[0][1] for line in lines])
pts = np.array([[np.cos(2 * angle), np.sin(2 * angle)]
for angle in angles], dtype=np.float32)
labels, centers = cv2.kmeans(pts, k, None, criteria, attempts, flags)[1:]
labels = labels.reshape(-1)
segmented = defaultdict(list)
for i, line in zip(range(len(lines)), lines):
segmented[labels[i]].append(line)
segmented = list(segmented.values())
I have converted this much till now and not able to understand how to convert rest of it.C++ code
vector<Vec2f> segmented;
Mat labels;
vector<Vec2f> angles;
for (int i = 0; i < lines.size(); i++) {
float angle = lines[i][1];
angles.push_back(angle);
}
Mat points(angles.size,2, );
for (int j = 0; j < angles.size(); j++) {
float angle = 2 * angles[j][1];
float c = cos(angle);
float s = sin(angle);
points[j][0] = c;
points[j][1] = s;
}
vector<Vec2f> labels = kmeans(points, k, labels,TermCriteria(TermCriteria::EPS + TermCriteria::MAX_ITER, 10, 1.0),10, KMEANS_RANDOM_CENTERS);
Please Help.