1
  • I have an image with an eye and points around the eye. For example 10 points. Now I want to crop that eye part.
  • But I don't know how can I do it.
    Please give me an idea.
Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Sagar Patel
  • 864
  • 1
  • 11
  • 22

1 Answers1

1

I suggest that you find a "bounding box" from the points you want to crop around. Then, you can use this method to crop the image.

Here's a sample code that should give you an idea on what to do:

// let's assume that you stored your 10 points in a QList
QList<QpointF> points;
// fill in "points"...
// generate a "bounding box" by finding the min/max in the x and y directions
const auto compareX = [] (const QpointF& p1, const QpointF& p2) {
    return p1.x() < p2.x();
};
const auto compareY = [] (const QpointF& p1, const QpointF& p2) {
    return p1.y() < p2.y();
};
const auto pMinX = std::min_element(points.begin(), points.end(), compareX);
const auto pMaxX = std::max_element(points.begin(), points.end(), compareX);
const auto pMinY = std::min_element(points.begin(), points.end(), compareY);
const auto pMaxY = std::max_element(points.begin(), points.end(), compareY);
cv::Rect boundingBox(pMinX->x(),
                     pMinY->y(),
                     pMaxX->x() - pMinX->x(),
                     pMaxY->y() - pMinY->y());
// get a view on the sub-image
cv::Mat croppedImage = originalImage(boundingBox);
maddouri
  • 3,737
  • 5
  • 29
  • 51