P
P
Pavel K2020-11-08 04:34:15
C++ / C#
Pavel K, 2020-11-08 04:34:15

How to translate this piece of Python code to C++?

I can't figure out how to rewrite this code from python to C++:

from scipy.spatial import distance as dist
import numpy as np
import cv2
def order(pts):   # Как понял, там массив точек x и y, предположительно 4
  sorted = pts[np.argsort(pts[:, 0]), :]   # Сортируем по X ?
  leftMost = sorted[:2, :]  # Берём 0 и 1?
  rightMost = sorted[2:, :] # Берём 2 и 3?
  leftMost = leftMost[np.argsort(leftMost[:, 1]), :]   # Сортируем по Y ?
  (tl, bl) = leftMost
  D = dist.cdist(tl[np.newaxis], rightMost, "euclidean")[0]
  (br, tr) = rightMost[np.argsort(D)[::-1], :]
  return np.array([tl, tr, br, bl], dtype="float32")


So far I've understood this:
std::vector<Point2d> orderPoints(std::vector<Point2d> pts)
{
    //-- Сортируем по X
    std::sort(pts.begin(), pts.end(), [](const Point2d &p1, const Point2d &p2){ return (p1.x<=p2.x); });

    std::vector<Point2d> leftMost = {pts[0], pts[1]};
    std::vector<Point2d> rightMost = {pts[2],pts[3]};

}


Next, I'm dumb. Tell me what's going on next?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jairman, 2020-11-08
@Jairman

Maybe I’ll say crap, but try to look at the code of the functions that you use, the libraries themselves, then rewrite these functions in c ++, it should be much easier

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question