Я собираю opencv 3.4 с Gstreamer MSV C 1.16.1, и теперь imread и VideoCapture не работают - PullRequest
0 голосов
/ 07 марта 2020

Я собираю OpenCV 3.4 с Gstreamer MSV C 1.16.1, используя Cmake и Visual Studio 10. Я включил каталог bin в переменную системного пути, добавил все дополнительные include и библиотеку в 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 site:

// 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.

1 Ответ

0 голосов
/ 09 марта 2020

Итак, ошибка была в том, что сразу после "имени файла присутствовал невидимый символ ('\ u202A'). Как только я удалил его, все работает нормально. Я нашел это из warning C4566: character represented by universal-character-name '\u202A' cannot be represented in the current code page (1252)

...