2017-01-16 33 views
-2

我想在Java中使用OpenCV做一些簡單的行人檢測。 這裏是我的代碼:在Java中的行人檢測

SimpleBlobDetector blobDetector; 
blobDetector.detect(mask, matOfKeyPoints); 
org.opencv.core.Scalar cores = new org.opencv.core.Scalar(255, 0, 0); 
org.opencv.features2d.Features2d.drawKeypoints(frame, matOfKeyPoints, frame, cores, Features2d.DRAW_RICH_KEYPOINTS); 

這確實一個非常堅實的工作,但邊框我讓周圍的行人實際上,我需要矩形

+0

把那個java關掉 – gpasch

回答

0

不幸的是,這些圓是內置的,並且沒有默認標誌來繪製矩形。見DRAW_RICH_KEYPOINTSdocumentation

但是,由於您已擁有關鍵點位置,因此您可以編寫自己的繪圖功能。 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); 
     } 
    } 
}