C++ BLOB OPENCV的ROI断言失败
我有一个程序,尝试使用simpleblobdetector检测一个blob,在检测到blob后,我尝试对blob进行ROI,以便我能够知道blob的RGB值的平均值。但大多数情况下,在运行程序或移动对象(因为这是网络摄像头输入)后,我会出现以下错误: 在引发“cv::Exception”的实例后调用terminate what():OpenCV(4.2.0)…/modules/core/src/matrix.cpp:465:错误:(-215:断言失败)0C++ BLOB OPENCV的ROI断言失败,c++,opencv,C++,Opencv,我有一个程序,尝试使用simpleblobdetector检测一个blob,在检测到blob后,我尝试对blob进行ROI,以便我能够知道blob的RGB值的平均值。但大多数情况下,在运行程序或移动对象(因为这是网络摄像头输入)后,我会出现以下错误: 在引发“cv::Exception”的实例后调用terminate what():OpenCV(4.2.0)…/modules/core/src/matrix.cpp:465:错误:(-215:断言失败)0 // filterByColor
// filterByColor
params.filterByColor = true;
params.blobColor = 255;
// Filter by Area.
params.filterByArea = true;
params.minArea = 4000;
params.maxArea = 100000;
// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.45;
// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.45;
// Filter by Inertia
params.filterByInertia = true;
params.minInertiaRatio = 0.01;
// Storage for blobs
vector<KeyPoint> keypoints;
// Set up detector with params
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
// Detect blobs
detector->detect( frameBrightness, keypoints);
Mat im_with_keypoints;
cv::Scalar mean;
drawKeypoints( frameBrightness, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
size_t i;
Point Coordinate;
for( i =0; i < keypoints.size(); i++ )
{
Coordinate = keypoints[i].pt ;
Rect r(Coordinate.x-(keypoints[i].size /2), Coordinate.y-(keypoints[i].size/2), keypoints[i].size, keypoints[i].size) ;
Mat roi(im_with_keypoints, r);
mean = cv::mean(roi);
qDebug() << "Blue" << mean[0] ;
qDebug() << "Green" << mean[1] ;
qDebug() << "Red" << mean[2] ;