roi的opencv错误断言
opencv error assertion with roi
我正在尝试使用HOG分类器检测人员和其他对象。我开始使用以下代码检测人员:
capt >> frame_capture;
capt1 >> frame_capture1;
cv::cvtColor(frame_capture1,gray, CV_RGB2GRAY);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(gray,contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
vector <Rect> listOfRectangles;
// detecting objects
listOfRectangles = drawBoundingBox(contours);
if(!frame_capture.empty()){
for (int i =0; i<listOfRectangles.size();++i)
{
//rectangle (frame_capture, listOfRectangles[i],Scalar(255,255,0),1,8,0); //! display detections
cv::Mat roi;
roi.create(frame_capture.size(),CV_8UC3);
cv::Mat image=imread("");
roi = image(listOfRectangles[i]);
cv::Mat window;
cv::resize(roi, window, cv::Size(64, 128));
hog.detect(window, foundLocations);
if (!foundLocations.empty())
{
cout << "person .." << endl;
}
}
//oVideoWriter.write(frame_capture);
imshow("video",frame_capture);
waitKey(25);
}
我得到了这个错误:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat
我用过这个链接:OpenCV:如何使用HOGDescriptionr::detect方法?
当您使用imread()
时,您正在传递一个空路径,因此找不到图像,cv::Mat image
也没有数据。在下一行中,你试图获得一个空图像的子图像(ROI),这就是为什么你会得到错误。
您需要正确初始化cv::Mat image
。您可以通过在该行之后添加一个简单的验证来检查是否一切正常,例如
if(! image.data ) // Check for invalid input
{
std::cout << "Could not open or find the image" << std::endl ;
return;
}
相关文章:
- OpenCV - Python 断言错误:SAD 算法 - 立体相机视差图计算
- 我收到一个断言错误,但是当我编写 cout 语句时,它会消失
- 尝试删除指向派生对象的基指针时断言错误
- Sysmalloc:使用向量的断言错误
- OpenCV CV 查找单应断言错误计数器 = > 4
- Mat的convertTo函数在OpenCV中将灰度图像的类型转换为CV_32F时抱怨断言错误
- 是什么导致我的C 代码中的断言错误
- 迭代器取消引用断言错误
- boost::shared_ptr 断言错误与 boost::asio:io_service
- CDao数据库断言错误
- STL 迭代器:断言错误
- 断言错误,字符串下标超出范围
- 调试断言错误-OpenCV
- 向量push_back会导致断言错误,但列表push_back有效
- 如何在子进程中禁用断言错误对话框
- OpenCV.norm中的断言错误
- 将功能区添加到现有的非功能区 mfc 项目 - 在 VS2010 中断言错误
- 访问指向像素openCV的指针时发生断言错误
- 断言错误,即使在使用 new 初始化字符指针后也是如此
- 使用结构向量 c++ 的断言错误