MacOSXのC++でOpenCV4.3.2を使用して、画像のリストをビデオファイルに変換しようとしています。プロジェクトはXCodeでコンパイルされています。コードを実行するたびに、次の出力が表示されます。
警告:空のムービーファイルコンテナを作成できませんでした。
ムービーファイルを正常に更新できませんでした。
最初の警告は次の結果です。
writer.open(argv[2],codec,fps,size);
そして、ムービーファイルの更新に関する2番目の部分は次のとおりです。
writer << im;
完全なコードは次のとおりです。
#include <cv.h>
#include <highgui.h>
int main( int argc, char** argv )
{
/*
Skipping unrelated code
*/
// Set FPS of movie
double fps = 30;
// Set frame size of movie
cv::Size size = cv::Size(1920,1080);
// VideoWriter stream to write images to
cv::VideoWriter writer;
int codec = CV_FOURCC('D', 'I', 'V', 'X');
std::cout << "Using codec " << codec << std::endl;
// Open VideoWriter stream
writer.open(argv[2],codec,fps,size);
// Verify that the VideoWriter is open
if(!writer.isOpened())
{
std::cout << "VideoWriter unable to open" << std::endl;
return -3;
}
// Structure to hold image
cv::Mat im;
for(int i = 0; i < photos.size(); i++)
{
// Read image from file
im = cv::imread(photos[i].c_str(), 1 );
if(im.data != NULL )
{
std::cout << "Writing " << photos[i] << " to file." << std::endl;
// Resize it to match video output
cv::resize(im,im,size);
// Write image to VideoWriter stream
writer << im;
}
else
{
std:: cout << "Unable to read file " << photos[i] << std::endl;
return -4;
}
}
return 0;
}
他の人にも同様のエラーがあるのを見たことがありますが、どのソリューションもそれを修正していません(コーデックの変更など)