不幸的是,這些圓是內置的,並且沒有默認標誌來繪製矩形。見DRAW_RICH_KEYPOINTS
documentation。
但是,由於您已擁有關鍵點位置,因此您可以編寫自己的繪圖功能。 drawKeypoints
函數的C++版本是here。下面是繪製矩形的新函數的簡明版本。
void drawKeypoints(InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage, const Scalar& _color)
{
bool isRandColor = _color == Scalar::all(-1);
std::vector<KeyPoint>::const_iterator it = keypoints.begin(),
end = keypoints.end();
for(; it != end; ++it)
{
Scalar color = isRandColor ? Scalar(rng(256), rng(256), rng(256)) : _color;
p=*it;
Point center(cvRound(p.pt.x * draw_multiplier), cvRound(p.pt.y * draw_multiplier));
int radius = cvRound(p.size/2 * draw_multiplier); // KeyPoint::size is a diameter
// draw RECTANGLES (actually squares) around keypoints with the keypoints size
rectangle(outImage, center + Point(-radius, -radius), center + Point(radius, radius), color, 1, LINE_AA, draw_shift_bits);
// draw orientation of the keypoint, if it is applicable
if(p.angle != -1)
{
float srcAngleRad = p.angle*(float)CV_PI/180.f;
Point orient(cvRound(cos(srcAngleRad)*radius),
cvRound(sin(srcAngleRad)*radius)
);
line(outImage, center, center+orient, color, 1, LINE_AA, draw_shift_bits);
}
}
}
把那個java關掉 – gpasch