金蕊泛流霞 发表于 2020-9-15 11:34:03

用c++编写opencv的程序遇到问题,请各位大佬帮助

#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>

using namespace cv;

int main() {
      Mat src, dst;
      src = imread("C:/Users/Administrator/Desktop/3.jpg");
      if (!src.data) {
                printf("没有图片!");
                return -1;
      }
      namedWindow("input image", CV_WINDOW_AUTOSIZE);
      imshow("input image", src);
      /*
      int cols = (src.cols - 1)*src.channels();
      int offsetx = src.channels();
      int rows = src.rows;
      dst = Mat::zeros(src.size(), src.type());
      for (int row = 1; row < rows; row++) {
                const uchar* previous = src.ptr<uchar>(row - 1);
                const uchar* current = src.ptr<uchar>(row);
                const uchar* next = src.ptr<uchar>(row + 1);
                uchar*output = dst.ptr<uchar>(row);
                for (int col = 1; col < offsetx; col++) {
                        output = saturate_cast<uchar>(5 * current - (current + current + previous + next));

                }
      }
      */
      Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 5, 0, -1, 0);
      filter2D(src, dst, src.depth(), kernel);
      namedWindow("change image output", CV_WINDOW_AUTOSIZE);
      imshow("change image output", dst);
      waitKey(0);
      return 0;
}


错误提示:OpenCV(3.4.2) Error: Assertion failed (this->it == ((const Mat_<_Tp>*)this->it.m)->end()) in cv::MatCommaInitializer_<ch
ar>::operator class cv::Mat_<char>, file g:\chengxu\opencv\opencv\build\include\opencv2\core\mat.inl.hpp, line 3299
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.2) Error: Assertion failed (this->it == ((const Mat_<_Tp>*)this->it.m)->end()) in cv::MatCommaInitializer_<ch
ar>::operator class cv::Mat_<char>, file g:\chengxu\opencv\opencv\build\include\opencv2\core\mat.inl.hpp, line 3299



菜鸡一个,求大佬解答
页: [1]
查看完整版本: 用c++编写opencv的程序遇到问题,请各位大佬帮助