mirror of
https://github.com/opencv/opencv.git
synced 2025-06-08 01:53:19 +08:00
videoio: fixed capture open order, added apiPrefernce to FFMPEG tests
This commit is contained in:
parent
e4aa2ccd66
commit
7628c143f4
@ -527,49 +527,35 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Ptr<IVideoCapture> IVideoCapture_create(const String& filename)
|
static Ptr<IVideoCapture> IVideoCapture_create(const String& filename, int apiPreference)
|
||||||
{
|
{
|
||||||
int domains[] =
|
bool useAny = (apiPreference == CAP_ANY);
|
||||||
{
|
Ptr<IVideoCapture> capture;
|
||||||
CAP_ANY,
|
|
||||||
#ifdef HAVE_GPHOTO2
|
#ifdef HAVE_GPHOTO2
|
||||||
CAP_GPHOTO2,
|
if (useAny || apiPreference == CAP_GPHOTO2)
|
||||||
#endif
|
|
||||||
#ifdef HAVE_MFX
|
|
||||||
CAP_INTEL_MFX,
|
|
||||||
#endif
|
|
||||||
-1, -1
|
|
||||||
};
|
|
||||||
|
|
||||||
// try every possibly installed camera API
|
|
||||||
for (int i = 0; domains[i] >= 0; i++)
|
|
||||||
{
|
{
|
||||||
Ptr<IVideoCapture> capture;
|
capture = createGPhoto2Capture(filename);
|
||||||
|
|
||||||
switch (domains[i])
|
|
||||||
{
|
|
||||||
case CAP_ANY:
|
|
||||||
capture = createMotionJpegCapture(filename);
|
|
||||||
break;
|
|
||||||
#ifdef HAVE_GPHOTO2
|
|
||||||
case CAP_GPHOTO2:
|
|
||||||
capture = createGPhoto2Capture(filename);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_MFX
|
|
||||||
case CAP_INTEL_MFX:
|
|
||||||
capture = makePtr<VideoCapture_IntelMFX>(filename);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (capture && capture->isOpened())
|
if (capture && capture->isOpened())
|
||||||
{
|
|
||||||
return capture;
|
return capture;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// failed open a camera
|
#endif
|
||||||
return Ptr<IVideoCapture>();
|
#ifdef HAVE_MFX
|
||||||
|
if (useAny || apiPreference == CAP_INTEL_MFX)
|
||||||
|
{
|
||||||
|
capture = makePtr<VideoCapture_IntelMFX>(filename);
|
||||||
|
if (capture && capture->isOpened())
|
||||||
|
return capture;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (useAny || apiPreference == CAP_OPENCV_MJPEG)
|
||||||
|
{
|
||||||
|
capture = createMotionJpegCapture(filename);
|
||||||
|
if (capture && capture->isOpened())
|
||||||
|
return capture;
|
||||||
|
}
|
||||||
|
if (capture && !capture->isOpened())
|
||||||
|
capture.release();
|
||||||
|
return capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Ptr<IVideoWriter> IVideoWriter_create(const String& filename, int apiPreference, int _fourcc, double fps, Size frameSize, bool isColor)
|
static Ptr<IVideoWriter> IVideoWriter_create(const String& filename, int apiPreference, int _fourcc, double fps, Size frameSize, bool isColor)
|
||||||
@ -625,7 +611,7 @@ bool VideoCapture::open(const String& filename, int apiPreference)
|
|||||||
CV_TRACE_FUNCTION();
|
CV_TRACE_FUNCTION();
|
||||||
|
|
||||||
if (isOpened()) release();
|
if (isOpened()) release();
|
||||||
icap = IVideoCapture_create(filename);
|
icap = IVideoCapture_create(filename, apiPreference);
|
||||||
if (!icap.empty())
|
if (!icap.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public:
|
|||||||
fps = 25;
|
fps = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoWriter writer(filename, tag, fps, frame_s);
|
VideoWriter writer(filename, CAP_FFMPEG, tag, fps, frame_s);
|
||||||
|
|
||||||
if (writer.isOpened() == false)
|
if (writer.isOpened() == false)
|
||||||
{
|
{
|
||||||
@ -194,7 +194,7 @@ public:
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string filename = ts->get_data_path() + "readwrite/ordinary.bmp";
|
string filename = ts->get_data_path() + "readwrite/ordinary.bmp";
|
||||||
VideoCapture cap(filename);
|
VideoCapture cap(filename, CAP_FFMPEG);
|
||||||
Mat img0 = imread(filename, 1);
|
Mat img0 = imread(filename, 1);
|
||||||
Mat img, img_next;
|
Mat img, img_next;
|
||||||
cap >> img;
|
cap >> img;
|
||||||
@ -242,7 +242,7 @@ public:
|
|||||||
std::string fileName = tempfile(stream.str().c_str());
|
std::string fileName = tempfile(stream.str().c_str());
|
||||||
|
|
||||||
files->operator[](i) = fileName;
|
files->operator[](i) = fileName;
|
||||||
writers->operator[](i) = new VideoWriter(fileName, VideoWriter::fourcc('X','V','I','D'), 25.0f, FrameSize);
|
writers->operator[](i) = new VideoWriter(fileName, CAP_FFMPEG, VideoWriter::fourcc('X','V','I','D'), 25.0f, FrameSize);
|
||||||
|
|
||||||
CV_Assert(writers->operator[](i)->isOpened());
|
CV_Assert(writers->operator[](i)->isOpened());
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ public:
|
|||||||
{
|
{
|
||||||
for (int i = range.start; i != range.end; ++i)
|
for (int i = range.start; i != range.end; ++i)
|
||||||
{
|
{
|
||||||
readers->operator[](i) = new VideoCapture(files->operator[](i));
|
readers->operator[](i) = new VideoCapture(files->operator[](i), CAP_FFMPEG);
|
||||||
CV_Assert(readers->operator[](i)->isOpened());
|
CV_Assert(readers->operator[](i)->isOpened());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user