Media foundation video i/o fixes.

Bug in Video for Windows capture init fixed;
Media Foundation based capture finalization fixed;
Highgui tests for video i/o updated.
pull/1040/head
Alexander Smorkalov 12 years ago
parent 996f02a531
commit 43122939cb
  1. 4
      modules/highgui/include/opencv2/highgui/highgui_c.h
  2. 35
      modules/highgui/src/cap.cpp
  3. 138
      modules/highgui/src/cap_msmf.cpp
  4. 4
      modules/highgui/src/cap_vfw.cpp
  5. 58
      modules/highgui/test/test_video_io.cpp

@ -558,9 +558,11 @@ CVAPI(int) cvGetCaptureDomain( CvCapture* capture);
/* "black box" video file writer structure */
typedef struct CvVideoWriter CvVideoWriter;
#define CV_FOURCC_MACRO(c1, c2, c3, c4) ((c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24))
CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4)
{
return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24);
return CV_FOURCC_MACRO(c1, c2, c3, c4);
}
#define CV_FOURCC_PROMPT -1 /* Open Codec Selection Dialog (Windows only) */

@ -199,23 +199,20 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
switch (domains[i])
{
#ifdef HAVE_MSMF
case CV_CAP_MSMF:
printf("Creating Media foundation capture\n");
capture = cvCreateCameraCapture_MSMF (index);
printf("Capture address %p\n", capture);
#ifdef HAVE_DSHOW
case CV_CAP_DSHOW:
capture = cvCreateCameraCapture_DShow (index);
if (capture)
return capture;
break;
#endif
#ifdef HAVE_DSHOW
case CV_CAP_DSHOW:
capture = cvCreateCameraCapture_DShow (index);
#ifdef HAVE_MSMF
case CV_CAP_MSMF:
capture = cvCreateCameraCapture_MSMF (index);
if (capture)
return capture;
break;
#endif
#ifdef HAVE_TYZX
case CV_CAP_STEREO:
capture = cvCreateCameraCapture_TYZX (index);
@ -223,14 +220,12 @@ CV_IMPL CvCapture * cvCreateCameraCapture (int index)
return capture;
break;
#endif
case CV_CAP_VFW:
#ifdef HAVE_VFW
case CV_CAP_VFW:
capture = cvCreateCameraCapture_VFW (index);
if (capture)
return capture;
#endif
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
capture = cvCreateCameraCapture_V4L (index);
if (capture)
@ -363,18 +358,14 @@ CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
if (! result)
result = cvCreateFileCapture_FFMPEG_proxy (filename);
#ifdef HAVE_MSMF
#ifdef HAVE_VFW
if (! result)
{
printf("Creating Media foundation based reader\n");
result = cvCreateFileCapture_MSMF (filename);
printf("Construction result %p\n", result);
}
result = cvCreateFileCapture_VFW (filename);
#endif
#ifdef HAVE_VFW
#ifdef HAVE_MSMF
if (! result)
result = cvCreateFileCapture_VFW (filename);
result = cvCreateFileCapture_MSMF (filename);
#endif
#ifdef HAVE_XINE
@ -422,14 +413,12 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
if(!fourcc || !fps)
result = cvCreateVideoWriter_Images(filename);
#ifdef HAVE_FFMPEG
if(!result)
result = cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color);
#endif
#ifdef HAVE_VFW
if(!result)
return cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color);
result = cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color);
#endif
#ifdef HAVE_MSMF

@ -840,9 +840,11 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid)
IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); // WAVE_FORMAT_MPEG_ADTS_AAC
return NULL;
}
FormatReader::FormatReader(void)
{
}
MediaType FormatReader::Read(IMFMediaType *pType)
{
UINT32 count = 0;
@ -888,9 +890,9 @@ ImageGrabber::ImageGrabber(unsigned int deviceID, bool synchronous):
ig_RIE(true),
ig_Close(false),
ig_Synchronous(synchronous),
ig_hFrameReady(synchronous ? CreateEvent(NULL, FALSE, FALSE, "ig_hFrameReady"): 0),
ig_hFrameGrabbed(synchronous ? CreateEvent(NULL, FALSE, TRUE, "ig_hFrameGrabbed"): 0),
ig_hFinish(synchronous ? CreateEvent(NULL, FALSE, FALSE, "ig_hFinish") : 0)
ig_hFrameReady(synchronous ? CreateEvent(NULL, FALSE, FALSE, NULL): 0),
ig_hFrameGrabbed(synchronous ? CreateEvent(NULL, FALSE, TRUE, NULL): 0),
ig_hFinish(CreateEvent(NULL, TRUE, FALSE, NULL))
{}
ImageGrabber::~ImageGrabber(void)
@ -898,15 +900,16 @@ ImageGrabber::~ImageGrabber(void)
printf("ImageGrabber::~ImageGrabber()\n");
if (ig_pSession)
{
printf("ig_pSession->Shutdown()");
printf("ig_pSession->Shutdown()\n");
ig_pSession->Shutdown();
}
CloseHandle(ig_hFinish);
if (ig_Synchronous)
{
CloseHandle(ig_hFrameReady);
CloseHandle(ig_hFrameGrabbed);
CloseHandle(ig_hFinish);
}
SafeRelease(&ig_pSession);
@ -1061,7 +1064,6 @@ HRESULT ImageGrabber::startGrabbing(void)
hr = S_OK;
goto done;
}
printf("media foundation event: %d\n", met);
if (met == MESessionEnded)
{
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionEnded \n", ig_DeviceID);
@ -1088,13 +1090,7 @@ HRESULT ImageGrabber::startGrabbing(void)
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Finish startGrabbing \n", ig_DeviceID);
done:
if (ig_Synchronous)
{
SetEvent(ig_hFinish);
}
SafeRelease(&ig_pSession);
SafeRelease(&ig_pTopology);
SetEvent(ig_hFinish);
return hr;
}
@ -1109,7 +1105,7 @@ void ImageGrabber::resumeGrabbing()
HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo)
{
ComPtr<IMFTopology> pTopology = NULL;
IMFTopology* pTopology = NULL;
ComPtr<IMFPresentationDescriptor> pPD = NULL;
ComPtr<IMFStreamDescriptor> pSD = NULL;
ComPtr<IMFMediaTypeHandler> pHandler = NULL;
@ -1117,7 +1113,7 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
ComPtr<IMFTopologyNode> pNode2 = NULL;
HRESULT hr = S_OK;
DWORD cStreams = 0;
CHECK_HR(hr = MFCreateTopology(pTopology.GetAddressOf()));
CHECK_HR(hr = MFCreateTopology(&pTopology));
CHECK_HR(hr = pSource->CreatePresentationDescriptor(pPD.GetAddressOf()));
CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams));
for (DWORD i = 0; i < cStreams; i++)
@ -1130,8 +1126,8 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
CHECK_HR(hr = pHandler->GetMajorType(&majorType));
if (majorType == MFMediaType_Video && fSelected)
{
CHECK_HR(hr = AddSourceNode(pTopology.Get(), pSource, pPD.Get(), pSD.Get(), pNode1.GetAddressOf()));
CHECK_HR(hr = AddOutputNode(pTopology.Get(), pSinkActivate, 0, pNode2.GetAddressOf()));
CHECK_HR(hr = AddSourceNode(pTopology, pSource, pPD.Get(), pSD.Get(), pNode1.GetAddressOf()));
CHECK_HR(hr = AddOutputNode(pTopology, pSinkActivate, 0, pNode2.GetAddressOf()));
CHECK_HR(hr = pNode1->ConnectOutput(0, pNode2.Get(), 0));
break;
}
@ -1140,7 +1136,7 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
CHECK_HR(hr = pPD->DeselectStream(i));
}
}
*ppTopo = pTopology.Get();
*ppTopo = pTopology;
(*ppTopo)->AddRef();
done:
@ -1286,9 +1282,15 @@ STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwS
(void)llSampleDuration;
(void)dwSampleSize;
WaitForSingleObject(ig_hFrameGrabbed, INFINITE);
//printf("ImageGrabber::OnProcessSample() -- begin\n");
HANDLE tmp[] = {ig_hFinish, ig_hFrameGrabbed, NULL};
printf("ImageGrabber::OnProcessSample() -- begin\n");
DWORD status = WaitForMultipleObjects(2, tmp, FALSE, INFINITE);
if (status == WAIT_OBJECT_0)
{
printf("OnProcessFrame called after ig_hFinish event\n");
return S_OK;
}
if(ig_RIE)
{
@ -1300,25 +1302,24 @@ STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwS
ig_RISecond->fastCopy(pSampleBuffer);
ig_RIOut = ig_RISecond;
}
ig_RIE = !ig_RIE;
printf("ImageGrabber::OnProcessSample() -- end\n");
//printf("ImageGrabber::OnProcessSample() -- end\n");
if (ig_Synchronous)
{
SetEvent(ig_hFrameReady);
}
else
{
ig_RIE = !ig_RIE;
}
return S_OK;
}
STDMETHODIMP ImageGrabber::OnShutdown()
{
if (ig_Synchronous)
{
SetEvent(ig_hFrameGrabbed);
}
SetEvent(ig_hFinish);
return S_OK;
}
@ -1387,6 +1388,8 @@ ImageGrabberThread::~ImageGrabberThread(void)
{
DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Destroing ImageGrabberThread\n", igt_DeviceID);
if (igt_Handle)
WaitForSingleObject(igt_Handle, INFINITE);
delete igt_pImageGrabber;
}
@ -1431,7 +1434,6 @@ void ImageGrabberThread::run()
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Emergency Stop thread\n", igt_DeviceID);
if(igt_func)
{
printf("Calling Emergency stop even handler\n");
igt_func(igt_DeviceID, igt_userData);
}
}
@ -3045,6 +3047,7 @@ CvCaptureFile_MSMF::CvCaptureFile_MSMF():
CvCaptureFile_MSMF::~CvCaptureFile_MSMF()
{
close();
MFShutdown();
}
@ -3109,7 +3112,7 @@ void CvCaptureFile_MSMF::close()
if (grabberThread)
{
isOpened = false;
SetEvent(grabberThread->getImageGrabber()->ig_hFrameReady);
SetEvent(grabberThread->getImageGrabber()->ig_hFinish);
grabberThread->stop();
delete grabberThread;
}
@ -3289,12 +3292,12 @@ bool CvCaptureFile_MSMF::grabFrame()
DWORD waitResult;
if (isOpened)
{
SetEvent(grabberThread->getImageGrabber()->ig_hFrameGrabbed);
HANDLE tmp[] = {grabberThread->getImageGrabber()->ig_hFrameReady, grabberThread->getImageGrabber()->ig_hFinish, 0};
waitResult = WaitForMultipleObjects(2, tmp, FALSE, INFINITE);
SetEvent(grabberThread->getImageGrabber()->ig_hFrameGrabbed);
}
return isOpened && (waitResult == WAIT_OBJECT_0);
return isOpened && grabberThread->getImageGrabber()->getRawImage()->isNew() && (waitResult == WAIT_OBJECT_0);
}
IplImage* CvCaptureFile_MSMF::retrieveFrame(int)
@ -3443,7 +3446,8 @@ private:
HRESULT WriteFrame(DWORD *videoFrameBuffer, const LONGLONG& rtStart, const LONGLONG& rtDuration);
};
CvVideoWriter_MSMF::CvVideoWriter_MSMF()
CvVideoWriter_MSMF::CvVideoWriter_MSMF():
initiated(false)
{
}
@ -3456,47 +3460,47 @@ const GUID CvVideoWriter_MSMF::FourCC2GUID(int fourcc)
{
switch(fourcc)
{
case 'dv25':
case CV_FOURCC_MACRO('d', 'v', '2', '5'):
return MFVideoFormat_DV25; break;
case 'dv50':
case CV_FOURCC_MACRO('d', 'v', '5', '0'):
return MFVideoFormat_DV50; break;
case 'dvc ':
case CV_FOURCC_MACRO('d', 'v', 'c', ' '):
return MFVideoFormat_DVC; break;
case 'dvh1':
case CV_FOURCC_MACRO('d', 'v', 'h', '1'):
return MFVideoFormat_DVH1; break;
case 'dvhd':
case CV_FOURCC_MACRO('d', 'v', 'h', 'd'):
return MFVideoFormat_DVHD; break;
case 'dvsd':
case CV_FOURCC_MACRO('d', 'v', 's', 'd'):
return MFVideoFormat_DVSD; break;
case 'dvsl':
case CV_FOURCC_MACRO('d', 'v', 's', 'l'):
return MFVideoFormat_DVSL; break;
case 'H263':
case CV_FOURCC_MACRO('H', '2', '6', '3'):
return MFVideoFormat_H263; break;
case 'H264':
case CV_FOURCC_MACRO('H', '2', '6', '4'):
return MFVideoFormat_H264; break;
case 'M4S2':
case CV_FOURCC_MACRO('M', '4', 'S', '2'):
return MFVideoFormat_M4S2; break;
case 'MJPG':
case CV_FOURCC_MACRO('M', 'J', 'P', 'G'):
return MFVideoFormat_MJPG; break;
case 'MP43':
case CV_FOURCC_MACRO('M', 'P', '4', '3'):
return MFVideoFormat_MP43; break;
case 'MP4S':
case CV_FOURCC_MACRO('M', 'P', '4', 'S'):
return MFVideoFormat_MP4S; break;
case 'MP4V':
case CV_FOURCC_MACRO('M', 'P', '4', 'V'):
return MFVideoFormat_MP4V; break;
case 'MPG1':
case CV_FOURCC_MACRO('M', 'P', 'G', '1'):
return MFVideoFormat_MPG1; break;
case 'MSS1':
case CV_FOURCC_MACRO('M', 'S', 'S', '1'):
return MFVideoFormat_MSS1; break;
case 'MSS2':
case CV_FOURCC_MACRO('M', 'S', 'S', '2'):
return MFVideoFormat_MSS2; break;
case 'WMV1':
case CV_FOURCC_MACRO('W', 'M', 'V', '1'):
return MFVideoFormat_WMV1; break;
case 'WMV2':
case CV_FOURCC_MACRO('W', 'M', 'V', '2'):
return MFVideoFormat_WMV2; break;
case 'WMV3':
case CV_FOURCC_MACRO('W', 'M', 'V', '3'):
return MFVideoFormat_WMV3; break;
case 'WVC1':
case CV_FOURCC_MACRO('W', 'V', 'C', '1'):
return MFVideoFormat_WVC1; break;
default:
return MFVideoFormat_H264;
@ -3516,19 +3520,15 @@ bool CvVideoWriter_MSMF::open( const char* filename, int fourcc,
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(hr))
{
printf("CoInitializeEx is successfull\n");
hr = MFStartup(MF_VERSION);
if (SUCCEEDED(hr))
{
printf("MFStartup is successfull\n");
hr = InitializeSinkWriter(filename);
if (SUCCEEDED(hr))
{
printf("InitializeSinkWriter is successfull\n");
initiated = true;
rtStart = 0;
MFFrameRateToAverageTimePerFrame((UINT32)fps, 1, &rtDuration);
printf("duration: %d\n", rtDuration);
}
}
}
@ -3556,13 +3556,9 @@ bool CvVideoWriter_MSMF::writeFrame(const IplImage* img)
if (!img)
return false;
printf("Writing not empty IplImage\n");
int length = img->width * img->height * 4;
printf("Image: %dx%d, %d\n", img->width, img->height, length);
DWORD* target = new DWORD[length];
printf("Before for loop\n");
for (int rowIdx = 0; rowIdx < img->height; rowIdx++)
{
char* rowStart = img->imageData + rowIdx*img->widthStep;
@ -3577,9 +3573,7 @@ bool CvVideoWriter_MSMF::writeFrame(const IplImage* img)
}
// Send frame to the sink writer.
printf("Before private WriteFrame call\n");
HRESULT hr = WriteFrame(target, rtStart, rtDuration);
printf("After private WriteFrame call\n");
if (FAILED(hr))
{
printf("Private WriteFrame failed\n");
@ -3588,8 +3582,6 @@ bool CvVideoWriter_MSMF::writeFrame(const IplImage* img)
}
rtStart += rtDuration;
printf("End of writing IplImage\n");
delete[] target;
return true;
@ -3681,7 +3673,8 @@ HRESULT CvVideoWriter_MSMF::InitializeSinkWriter(const char* filename)
{
hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
}
if (SUCCEEDED(hr))
if (SUCCEEDED(hr))
{
hr = sinkWriter->SetInputMediaType(streamIndex, mediaTypeIn.Get(), NULL);
}
@ -3697,7 +3690,6 @@ HRESULT CvVideoWriter_MSMF::InitializeSinkWriter(const char* filename)
HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG& Start, const LONGLONG& Duration)
{
printf("Private WriteFrame(%p, %llu, %llu)\n", videoFrameBuffer, Start, Duration);
ComPtr<IMFSample> sample;
ComPtr<IMFMediaBuffer> buffer;
@ -3712,13 +3704,11 @@ HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG&
// Lock the buffer and copy the video frame to the buffer.
if (SUCCEEDED(hr))
{
printf("MFCreateMemoryBuffer successfull\n");
hr = buffer->Lock(&pData, NULL, NULL);
}
if (SUCCEEDED(hr))
{
printf("Before MFCopyImage(%p, %d, %p, %d, %d %d)\n", pData, cbWidth, videoFrameBuffer, cbWidth, cbWidth, videoHeight);
hr = MFCopyImage(
pData, // Destination buffer.
cbWidth, // Destination stride.
@ -3727,21 +3717,16 @@ HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG&
cbWidth, // Image width in bytes.
videoHeight // Image height in pixels.
);
printf("After MFCopyImage()\n");
}
printf("Before buffer.Get()\n");
if (buffer)
{
printf("Before buffer->Unlock\n");
buffer->Unlock();
printf("After buffer->Unlock\n");
}
// Set the data length of the buffer.
if (SUCCEEDED(hr))
{
printf("MFCopyImage successfull\n");
hr = buffer->SetCurrentLength(cbBuffer);
}
@ -3758,24 +3743,19 @@ HRESULT CvVideoWriter_MSMF::WriteFrame(DWORD *videoFrameBuffer, const LONGLONG&
// Set the time stamp and the duration.
if (SUCCEEDED(hr))
{
printf("Sample time: %d\n", Start);
hr = sample->SetSampleTime(Start);
}
if (SUCCEEDED(hr))
{
printf("Duration: %d\n", Duration);
hr = sample->SetSampleDuration(Duration);
}
// Send the sample to the Sink Writer.
if (SUCCEEDED(hr))
{
printf("Setting writer params successfull\n");
hr = sinkWriter->WriteSample(streamIndex, sample.Get());
}
printf("Private WriteFrame(%d, %p) end with status %u\n", streamIndex, sample.Get(), hr);
return hr;
}

@ -613,8 +613,10 @@ bool CvVideoWriter_VFW::open( const char* filename, int _fourcc, double _fps, Cv
close();
return false;
}
return true;
}
return true;
else
return false;
}

@ -57,27 +57,27 @@ string fourccToString(int fourcc)
#ifdef HAVE_MSMF
const VideoFormat g_specific_fmt_list[] =
{
/* VideoFormat("avi", 'dv25'),
VideoFormat("avi", 'dv50'),
VideoFormat("avi", 'dvc '),
VideoFormat("avi", 'dvh1'),
VideoFormat("avi", 'dvhd'),
VideoFormat("avi", 'dvsd'),
VideoFormat("avi", 'dvsl'),
VideoFormat("avi", 'M4S2'), */
VideoFormat("wmv", 'WMV3'),
// VideoFormat("avi", 'H264'),
// VideoFormat("avi", 'MJPG'),
// VideoFormat("avi", 'MP43'),
// VideoFormat("avi", 'MP4S'),
// VideoFormat("avi", 'MP4V'),
/* VideoFormat("avi", 'MPG1'),
VideoFormat("avi", 'MSS1'),
VideoFormat("avi", 'MSS2'),
VideoFormat("avi", 'WMV1'),
VideoFormat("avi", 'WMV2'),
VideoFormat("avi", 'WMV3'),
VideoFormat("avi", 'WVC1'), */
/*VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', '2', '5')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', '5', '0')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'c', ' ')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'h', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 'h', 'd')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 's', 'd')),
VideoFormat("wmv", CV_FOURCC_MACRO('d', 'v', 's', 'l')),
VideoFormat("wmv", CV_FOURCC_MACRO('H', '2', '6', '3')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', '4', 'S', '2')),
VideoFormat("avi", CV_FOURCC_MACRO('M', 'J', 'P', 'G')),
VideoFormat("mp4", CV_FOURCC_MACRO('M', 'P', '4', 'S')),
VideoFormat("mp4", CV_FOURCC_MACRO('M', 'P', '4', 'V')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'P', '4', '3')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'P', 'G', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'S', 'S', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('M', 'S', 'S', '2')),*/
//VideoFormat("avi", CV_FOURCC_MACRO('H', '2', '6', '4')),
VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '1')),
VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '2')),
VideoFormat("wmv", CV_FOURCC_MACRO('W', 'M', 'V', '3')),
//VideoFormat("wmv", CV_FOURCC_MACRO('W', 'V', 'C', '1')),
VideoFormat()
};
#else
@ -269,19 +269,19 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt
for(;;)
{
IplImage * img = cvQueryFrame( cap );
IplImage* img = cvQueryFrame( cap );
if (!img)
break;
frames.push_back(Mat(img).clone());
if (writer == 0)
if (writer == NULL)
{
writer = cvCreateVideoWriter(tmp_name.c_str(), fmt.fourcc, 24, cvGetSize(img));
if (writer == 0)
if (writer == NULL)
{
ts->printf(ts->LOG, "can't create writer (with fourcc : %d)\n",
ts->printf(ts->LOG, "can't create writer (with fourcc : %s)\n",
cvtest::fourccToString(fmt.fourcc).c_str());
cvReleaseCapture( &cap );
ts->set_failed_test_info(ts->FAIL_MISMATCH);
@ -317,18 +317,22 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt
double psnr = PSNR(img1, img);
if (psnr < thresDbell)
{
printf("Too low psnr = %gdb\n", psnr);
ts->printf(ts->LOG, "Too low frame %d psnr = %gdb\n", i, psnr);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
//imwrite("original.png", img);
//imwrite("after_test.png", img1);
//Mat diff;
//absdiff(img, img1, diff);
//imwrite("diff.png", diff);
ts->set_failed_test_info(ts->FAIL_MISMATCH);
break;
}
}
printf("Before saved release for %s\n", tmp_name.c_str());
cvReleaseCapture( &saved );
printf("After release\n");
ts->printf(ts->LOG, "end test function : ImagesVideo \n");
}

Loading…
Cancel
Save