[英]Opencv2.4.9 SimpleBlobDetector mask does not work
我仔細閱讀過該網站的說明,但無濟於事...希望有人知道答案。
我正在使用simpleBlobDetector來跟蹤一些斑點。 我想通過detect方法指定一個遮罩,但是由於某種原因,該遮罩似乎不起作用-我的關鍵點出現在整個圖像上。 以下是我的代碼片段:
Mat currFrame;
Mat mask;
Mat roi;
cv::Ptr<cv::FeatureDetector> blob_detector = new cv::SimpleBlobDetector(params);//custom set of params I've left out for legibility
blob_detector->create("SimpleBlob");
vector<cv::KeyPoint> myblob;
while(true)
{
captured >> currFrame; // get a new frame from camera >> is grab and retrieve in one go, note grab does not allow frame to be modified but edges can be
// do nothing if frame is empty
if(currFrame.empty())
{
break;
}
/******************** make mask***********************/
mask = Mat::zeros(currFrame.size(),CV_8U);
roi = Mat(mask,Rect(400,400,400,400));
roi = 255;
/******************** image cleanup with some filters*/
GaussianBlur(currFrame,currFrame, Size(5,5), 1.5, 1.5);
cv::medianBlur(currFrame,currFrame,3);
blob_detector->detect(fgMaskMOG,myblob,mask);//fgMaskMOG is currFrame after some filtering and background subtraction
cv::drawKeypoints(fgMaskMOG,myblob,fgMaskMOG,Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
imshow("mogForeground", fgMaskMOG);
imshow("original", currFrame);
imshow("mask",mask);
if(waitKey(1) != -1)
break;
}
事實是,我確認通過使用如下所述的SurfFeatureDetector正確地制作了我的遮罩( OpenCV:如何使用遮罩參數進行特征點檢測(SURF) )如果有人可以看到我的遮罩出了什么問題,我將非常感謝您的幫助。 抱歉,代碼混亂!
我遇到了同樣的問題,但是找不到解決方案,因此我自己檢查了面具來解決了這個問題:
blob_detector->detect(img, keypoints);
std::vector<cv::KeyPoint> keypoints_in_range;
for (cv::KeyPoint &kp : keypoints)
if (mask.at<char>(kp.pt) > 0)
keypoints_in_range.push_back(kp)
我發現我opencv2.4.8此代碼:
void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints, const cv::Mat&) const
{
//TODO: support mask
keypoints.clear();
Mat grayscaleImage;
這意味着尚不支持此選項。
過濾關鍵點的解決方案不是很好,因為這很費時間(您必須檢測整個圖像中的斑點)。
更好的解決方法是在檢測之前削減ROI,並在檢測之后移動每個KeyPoint:
int x = 500;
int y = 200;
int width = 700;
int height = 700;
Mat roi = frame(Rect(x,y,width,height));
blob_detector.detect(roi, keypoints);
for (KeyPoint &kp : keypoints)
{
kp.pt.x +=x;
kp.pt.y +=y;
}
drawKeypoints(frame, keypoints, frame,Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.