打开CV断言失败错误 [英] Open CV Assertion Failed error

查看:364
本文介绍了打开CV断言失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前收到此错误:

OpenCV Error: Assertion failed (0 <= i && i < (int)vv.size()) in getMat_, file 

/tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/core/src/matrix.cpp, line 1200

terminate called after throwing an instance of 'cv::Exception'

what():  /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/core/src/matrix.cpp:1200:

error: (-215) 0 <= i && i < (int)vv.size() in function getMat_

代码

我目前正在处理此代码,试图在我从机器人获取的视频供稿中查找圈子.经过一番巧妙的评论后,我发现,每当霍夫圆(Hough Circles)(cv::HoughCircles)确实检测到圆时,都会出现上述错误.

Code

I am currently working on this code, trying to find circles in a video feed I am acquiring from a robot. After some clever commenting, I discovered that whenever Hough Circles (cv::HoughCircles) does detect a circle, I get the error as indicated above.

cv::Size strel_size;
strel_size.width = 3; 
strel_size.height = 3; 
cv::Mat strel = cv::getStructuringElement(cv::MORPH_ELLIPSE, 
                    strel_size);
cv::morphologyEx(img_bin, intr_ptr, cv::MORPH_OPEN, strel,
        cv::Point(-1,-1), 3);

//cv::medianBlur(intr_ptr, copy_ptr, 7);
cv::bitwise_not(intr_ptr,intr_ptr);
cv::GaussianBlur(intr_ptr, intr_ptr, cv::Size(7,7), 2, 2);
cv::vector< cv::vector<int> > circles;
cv::HoughCircles(intr_ptr, circles, CV_HOUGH_GRADIENT, 1, 70, 140, 15, 20, 
                    400);

for(size_t i = 0; i < circles.size(); i++) {
    cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
    int radius = cvRound(circles[i][2]);
    cv::circle(cv_ptr->image, center, 3, cv::Scalar(0,255,0), -1, 8, 0);
    cv::circle(cv_ptr->image, center, radius + 1, cv::Scalar(0,255,0), 
               2, 8, 0);
    ROS_INFO("x: %d, y: %d, r: %d\n", center.x, center.y, radius);
}

//cv::imshow(OPENCV_WINDOW1, cv_ptr->image);
cv::imshow(OPENCV_WINDOW2, cv_ptr->image);
//cv::imshow(OPENCV_WINDOW3, copy_ptr->image);

cv::waitKey(3);

背景

我目前正在尝试在运行 Ubuntu MATE 16.04 LTS Raspberry Pi 上使用 ROS 构建自动无人机.到目前为止,解决了识别红色圆圈的计算机视觉问题.

Background

I am currently trying to build an autonomous drone using ROS on my Rapsberry Pi which is running an Ubuntu MATE 16.04 LTS. Solving the Computer Vision problem of recognizing red circles as of now.

推荐答案

发生错误是因为圆的输出数组格式不正确. cv :: HoughCircles 函数采用cv: :vector,不是vectors的vector作为圆形数组的类型.而且这些值是浮点数,而不是整数.

The error happens because the output array for the circles doesn't have the correct format. The cv::HoughCircles function takes a cv::vector, not a vector of vectors as type for the circle array. Also the values are float, not integer.

http://docs.opencv.org上比较本教程/3.1.0/d4/d70/tutorial_hough_circle.html

(发生的情况是,当cv :: HoughCircles找到一个圆时,它将尝试访问vec3f矩阵-但是,在您的情况下,这是一个整数的(空)cv :: vector,因此大小声明失败.)

(What happens is that when cv::HoughCircles finds a circle, it attempts to access the vec3f matrix - however in your case this is an (empty) cv::vector of integers and hence the size-assertion fails.)

这篇关于打开CV断言失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆