使用wsl2的Ubuntu20.04运行opencv代码,运行至cv::imshow时报以下错误,请问如何解决
#include <iostream>
#include "opencv4/opencv2/opencv.hpp"
#include "opencv4/opencv2/highgui.hpp"
#include "opencv4/opencv2/imgproc.hpp"
using namespace cv;
using namespace std;
int main() {
cv::Mat image = cv::imread("test.jpg");
if(image.empty()) {
std::cerr << "Error loading image" << std::endl;
return -1;
}
std::cout << "OpenCV测试成功!" << std::endl;
std::cout << "图像尺寸: " << image.cols << "x" << image.rows << std::endl;
std::cout << "通道数: " << image.channels() << std::endl;
cv::imshow("测试窗口", image);
cv::waitKey(0);
return 0;
}
