OpenCV-Python
请问这个error是为什么啊,路径没有中文
这个错误是因为在使用cv2.imshow()函数时,传递的图像大小为0,导致无法显示图像。可能是因为读取图像时出现了问题,或者图像路径不正确。您可以检查一下图像路径是否正确,以及是否成功读取了图像。
最近编写如下代码,运行时窗口一闪而过,最后终端报出错误Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == _sz) in create
。
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
int main()
{
const std::string name = "image";
cv::namedWindow(name, cv::WINDOW_AUTOSIZE);
int w = 100, h = 300, y = 50;
// 黑图白线
cv::Mat img1(w, h, CV_8UC1, cv::Scalar(0)); // cv::Mat img = cv::Mat::zeros(w, h, CV_8UC1);
cv::line(img1, cv::Point(0, y), cv::Point(img1.cols, y), cv::Scalar(255), 2);
// 白图黑线
cv::Mat img2(w, h, CV_8UC1, cv::Scalar(255)); // cv::Mat img = cv::Mat::ones(w, h, CV_8UC1) * 255;
cv::line(img2, cv::Point(0, y), cv::Point(img2.cols, y), cv::Scalar(0), 2);
// 蓝图绿线
cv::Mat img3(w, h, CV_8UC3, cv::Scalar(255, 0, 0));
cv::line(img3, cv::Point(0, y), cv::Point(img3.cols, y), cv::Scalar(0, 255, 0), 2);
// 三张图片合并到一张图片上显示
cv::Mat img(3 * w, h, CV_8UC3);
cv::cvtColor(img1, img(cv::Rect(0, 0, w, h)), cv::COLOR_GRAY2BGR);
cv::cvtColor(img2, img(cv::Rect(w, 0, w, h)), cv::COLOR_GRAY2BGR);
img3.copyTo(img(cv::Rect(2 * w, 0, w, h)));
cv::imshow(name, img);
cv::waitKey();
return 0;
}
终端错误提示:
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.10) Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == _sz) in create, file D:\opencv3410\sources\modules\core\src\matrix_wrap.cpp, line 1194
类似的错误:
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.10) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat, file D:\opencv3410\sources\modules\core\src\matrix.cpp, line 466