我在OpenCV附带的SimpleBlobDetector工具中使用filterByColor功能时遇到了问题。 make并没有给我任何错误,但是当我尝试运行程序时,它会在blobme.detect()处发生段错误。
当我使用filterByArea时它工作正常,它只是filterByColor让我头疼。
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#define ACTIVE_CHANNEL 2
int main(int argc, char* argv[])
{
if (argc != 3)
{
std::cout << "./image_proc <file> <thresh> (-1 for default)" << std::endl;
return -1;
}
cv::Mat test_im = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
cv::Mat hsvim, outim, channels[3], descriptor;
std::vector<cv::KeyPoint> keypoints;
// Convert to HSV
cv::cvtColor(test_im, hsvim, CV_RGB2HSV);
cv::split(hsvim, channels);
cv::SimpleBlobDetector::Params params;
params.filterByInertia = false;
params.filterByConvexity = false;
params.filterByColor = true;
params.filterByCircularity = false;
params.filterByArea = false;
params.blobColor = 255;
//params.minArea = 100.0f;
//params.maxArea = 500.0f;
// Trying to use blob detector
cv::SimpleBlobDetector blobme(params);
blobme.detect(channels[ACTIVE_CHANNEL], keypoints);
// Print keypoints
cv::drawKeypoints(channels[ACTIVE_CHANNEL], keypoints, outim);
// Display
cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);
cv::imwrite("imout.jpg", outim);
cv::imshow("Display window", outim);
cv::waitKey(0);
return 0;
}