- 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.
Asked
Active
Viewed 564 times
1

Angie Quijano
- 4,167
- 3
- 25
- 30

Sagar Patel
- 864
- 1
- 11
- 22
-
1The same as you would for any set of points. Bounding rectangle, then crop to that rectangle – user3791372 Oct 20 '15 at 08:55
1 Answers
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
-
-
-
-
@SagarPatel: it's really simple just copy `x` and `y`. e.g. `cv::Point newPoint(qPoint.x(), qPoint.y());` – maddouri Oct 23 '15 at 09:58
-
@SagarPatel If what I've posted solves your problem, consider marking it as a solution. – maddouri Oct 23 '15 at 09:59
-
-
@865719-Can u plz tell me how to enable c++11 in eclipse Luna.Because auto is not working currently.It's showing compareX does not name a type. – Sagar Patel Oct 24 '15 at 05:12
-
Add `-std=c++11` to your C++ compiler flags (I assume that you're using gcc or clang) – maddouri Oct 24 '15 at 08:27