断言在我的OpenCV程序中失败了

时间:2017-01-04 04:21:39

标签: opencv

我的节目是另一版的OpenCV Harris和Shi-Tomasi角点检测。

我刚刚添加了一些代码,将图像角点检测更改为视频角点检测。然而,它出现了一个我无法处理的错误。 (cv::Exception)

这是我的计划:

#include "stdafx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;

double Harris_minVal;
double Harris_maxVal;
double ShiTomasi_minVal;
double ShiTomasi_maxVal;
int Harris_qualityLevel = 50;
int ShiTomasi_qualityLevel = 50;
int max_qualityLevel = 100;
RNG rng(12345);
const char* Harris_window = "Harris Corner Detection";
const char* ShiTomasi_window = "ShiTomasi Corner Detection";
Mat frame, frame_gray, Harris_dst, Harris_copy, ShiTomasi_dst, ShiTomasi_copy,Mc;

void HarrisFunction(int, void*);
void ShiTomasiFunction(int, void*);
int main()
{
    VideoCapture capture(0);
    while (1) {
        capture >> frame;
        cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
        int blockSize = 3;
        int kSize = 3;
        Harris_dst = Mat::zeros(frame_gray.size(), CV_32FC(6));
        Mc = Mat::zeros(frame_gray.size(), CV_32FC1);
        cornerEigenValsAndVecs(frame_gray, Harris_dst, blockSize, kSize, BORDER_DEFAULT);
        for (int j = 0; j < frame_gray.rows; j++) {
            for (int i = 0; i < frame_gray.cols; i++) {
                float lambda_1 = Harris_dst.at<Vec6f>(j, i)[0];
                float lambda_2 = Harris_dst.at<Vec6f>(j, i)[1];
                Mc.at<float>(j, i) = lambda_1*lambda_2 - 0.04f*pow((lambda_1 + lambda_2), 2);

            }
        }
        minMaxLoc(Mc, &Harris_minVal, &Harris_maxVal, 0, 0, Mat());
        namedWindow(Harris_window, WINDOW_AUTOSIZE);
        createTrackbar("质量:", Harris_window, &Harris_qualityLevel, max_qualityLevel, HarrisFunction);
        HarrisFunction(0, 0);

        ShiTomasi_dst = Mat::zeros(frame_gray.size(), CV_32FC1);
        cornerEigenValsAndVecs(frame_gray, ShiTomasi_dst, blockSize, kSize, BORDER_DEFAULT);
        minMaxLoc(ShiTomasi_dst, &ShiTomasi_minVal, &ShiTomasi_maxVal, 0, 0, Mat());
        namedWindow(ShiTomasi_window, WINDOW_AUTOSIZE);
        createTrackbar(" 质量:", ShiTomasi_window, &ShiTomasi_qualityLevel, max_qualityLevel, ShiTomasiFunction);
        ShiTomasiFunction(0, 0);

    }
    return 0;
}

void HarrisFunction(int, void*) {
    Harris_copy = frame.clone();
    if (Harris_qualityLevel < 1) {
        Harris_qualityLevel = 1;
    }
    for (int j = 0; j <= frame_gray.rows; j++) {
        for (int i = 0; i <= frame_gray.cols; i++) {
            if (Mc.at<float>(j, i) > Harris_minVal + (Harris_maxVal - Harris_minVal)*(Harris_qualityLevel / max_qualityLevel))
            {
                circle(Harris_copy, Point(i, j), 4, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)),1,8,0);
            }
        }
    }
    imshow(Harris_window, Harris_copy);
    waitKey(30);
}

void ShiTomasiFunction(int, void*) {
    ShiTomasi_copy = frame.clone();
    if (ShiTomasi_qualityLevel < 1) {
        ShiTomasi_qualityLevel = 1;
    }
    for (int j = 0; j <= frame_gray.rows; j++) {
        for (int i = 0; i <= frame_gray.cols; i++) {
            if (ShiTomasi_dst.at<float>(j, i) > ShiTomasi_minVal + (ShiTomasi_maxVal - ShiTomasi_minVal)*(ShiTomasi_qualityLevel / max_qualityLevel))
            {
                circle(ShiTomasi_copy, Point(i, j), 4, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 1, 8, 0);
            }
        }
    }
    imshow(ShiTomasi_window, ShiTomasi_copy);
    waitKey(30);
}

我的调试后,问题出现在imshow(Harris_window,Harris_copy)

之前
  

OpenCV错误:断言失败(dims&lt; = 2&amp;&amp; data&amp;&amp;(unsigned)i0&lt;(unsigned)size.p [0]&amp;&amp;(unsigned)(i1 * DataType&lt; _Tp&gt; ; :: channels)&lt;(unsigned)(size.p [1] * channels())&amp;&amp;((((sizeof(size_t)&lt;&lt; 28)| 0x8442211)&gt;&gt;((DataType&lt ; _Tp&gt; :: depth)&amp;((1 <&lt; 3) - 1))* 4)&amp; 15)== elemSize1())在cv :: Mat :: at,提交:\ opencv \ build \ include \ opencv2 \ core \ mat.inl.hpp,第894行

上半部分是面板窗口写的内容。

0 个答案:

没有答案