我使用Cmake和Visual Studio 10使用Gstreamer MSVC 1.16.1构建OpenCV 3.4。我在系统路径变量中包含了bin目录,并向Visual Studio添加了所有其他包含和库。现在,当我尝试读取映像以测试OpenCV是否正确安装时,它将引发错误:OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file .../opencv/modules/highgui/src/window.cpp
代码是:
Mat image1;
image1 = imread("D:\\Capture2.JPG");
if(! image1.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
}
imshow("Image",image1);
cvWaitKey(0);
return 0;
现在,我尝试使用来自openCV网站的演示代码播放视频:
// opencv_3.4_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
// Create a VideoCapture object and open the input file
// If the input is the web camera, pass 0 instead of the video file name
VideoCapture cap("Wildlife.mp4");
// Check if camera opened successfully
if(!cap.isOpened()){
cout << "Error opening video stream or file" << endl;
return -1;
}
while(1){
Mat frame;
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty())
break;
// Display the resulting frame
imshow( "Frame", frame );
// Press ESC on keyboard to exit
char c=(char)waitKey(25);
if(c==27)
break;
}
// When everything done, release the video capture object
cap.release();
// Closes all the frames
destroyAllWindows();
return 0;
}
程序正在正确构建,但运行时出现以下错误:
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:808)
warning: ?Wildlife.mp4 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:809)
GStreamer: error opening bin syntax error
哪里都有错误,因为它们都是最简单的OpenCV程序。
所以错误是,在文件名的“之后有一个不可见的字符('\ u202A')。删除该文件后,一切运行正常。我从warning C4566: character represented by universal-character-name '\u202A' cannot be represented in the current code page (1252)