答案 0 :(得分:1)
我建议你找一个"边界框"从你想要裁剪的点。然后,您可以使用this method裁剪图像。
这是一个示例代码,可以让您了解该怎么做:
// 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);