我正在尝试分别在所有颜色通道中检测图像中的圆心。我的代码看起来像这样:
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv2/opencv.hpp"
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
//#include "features2d.hpp"
using namespace cv;
using namespace std;
vector<KeyPoint> keypoints;
Mat imageSource;
Mat colorChannels[3];
int main(int argc, char* argv[])
{
SimpleBlobDetector::Params params;
params.minDistBetweenBlobs = 50;
params.filterByArea = true;
params.minArea = 50000;
params.filterByColor = true;
params.blobColor = 255;
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create();
imageSource = imread("opencv-logo.jpg", CV_LOAD_IMAGE_COLOR);
split(imageSource, colorChannels);
threshold(colorChannels[1], colorChannels[1], 100, 255, THRESH_BINARY);
bitwise_not(colorChannels[1], colorChannels[1]);
detector->detect(colorChannels[1], keypoints);
int number = keypoints.size();
printf("%d\n", number);
namedWindow("Original", WINDOW_AUTOSIZE);
imshow("Original", colorChannels[1]);
cvWaitKey(0);
return 0;
}
但每次我尝试运行它时,输出不同的矢量大小,如-592369722或1062631863 - 没什么正常的。尝试使用blobdetector的参数,但结果是一样的。如果我尝试取消注释#include "features2d.hpp"
,整个程序就会崩溃。
我的OpenCV版本是3.4.1。
我该如何解决这个问题?