我试图检测视频中的方形,应用程序崩溃并显示以下错误。
OpenCV错误:mixChannels中的断言失败(j< nsrcs&& src [j] .depth()== depth),文件/Users/alexandershishkov/opencv2.4.3rc/opencv/modules/core/src /convert.cpp,第472行 libc ++ abi.dylib:以cv类型的未捕获异常终止::异常:/Users/alexandershishkov/opencv2.4.3rc/opencv/modules/core/src/convert.cpp:472:错误:( - 215)j&lt ; nsrcs&& src [j] .depth()==功能mixChannels中的深度
这是代码。
vector<vector<cv::Point> > squares;
cvtColor(image,image,CV_BGR2GRAY);
GaussianBlur(image,image,cv::Size(9,11),0,0);
find_squares(image, contours);
void find_squares(Mat& image, vector<vector<cv::Point> >& squares)
{
Mat blurred(image);
medianBlur(image, blurred, 9);
Mat gray0(blurred.size(), CV_8U), gray;
vector<vector<cv::Point> > contours;
for (int c = 0; c < 3; c++)
{
int ch[] = {c, 0};
mixChannels(&blurred, 1, &gray0, 1, ch, 1);
const int threshold_level = 2;
for (int l = 0; l < threshold_level; l++)
{
if (l == 0)
{
Canny(gray0, gray, 10, 20, 3);
dilate(gray, gray, Mat(), cv::Point(-1,-1));
}
else
{
gray = gray0 >= (l+1) * 255 / threshold_level;
}
findContours(gray, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
vector<cv::Point> approx;
for (size_t i = 0; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);
if (approx.size() == 4 &&
fabs(contourArea(Mat(approx))) > 1000 &&
isContourConvex(Mat(approx)))
{
double maxCosine = 0;
for (int j = 2; j < 5; j++)
{
double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
maxCosine = MAX(maxCosine, cosine);
}
if (maxCosine < 0.3)
squares.push_back(approx);
}
}
}
}
}
答案 0 :(得分:0)
模糊和灰色0是单通道图像。因此,您尝试复制第二和第三个模糊图像通道,这些通道不会退出!错误应该是因为这个。
我希望它有所帮助。我对其余的代码一无所知,你想做什么。