C++ 带roi的opencv错误断言
我正在尝试使用HOG分类器检测人员和其他对象。我首先使用以下代码检测人员:C++ 带roi的opencv错误断言,c++,opencv,C++,Opencv,我正在尝试使用HOG分类器检测人员和其他对象。我首先使用以下代码检测人员: capt >> frame_capture; capt1 >> frame_capture1; cv::cvtColor(frame_capture1,gray, CV_RGB2GRAY); vector<vector<Point> > contours; vector<Vec4i> hierarchy; find
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);
}
capt>>帧捕获;
capt1>>帧捕获1;
cv::CVT颜色(帧捕获1,灰色,cv\U RGB2灰色);
矢量等值线;
向量层次;
findContours(灰色、轮廓、层次、CV_RETR_外部、CV_链_近似、简单、点(0,0));
矩形向量列表;
//探测对象
listOfRectangles=绘图边界框(等高线);
如果(!frame_capture.empty()){
对于(int i=0;i当您使用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;
}
if(!image.data)//检查输入是否无效
{
标准::cout
if(! image.data ) // Check for invalid input
{
std::cout << "Could not open or find the image" << std::endl ;
return;
}