Damien Dusha | 5 Oct 2010 04:20
Picon

Re: dropping frames. possible bug in libdc1394 ?

Hello,

On Wed, Sep 22, 2010 at 6:10 PM, Michael Joachimiak
<mjoachimiak@...> wrote:
> I am grabbing from 1394 IIDC cameras.
>
> From time to time I get very high latency - a bit more than 1s. The frames
> are dropped of course after that.
> How I can debug it more?
> My acquisition loop is not a problem - in the worst case it takes only 40ms
> per frame in 15Hz capturing.
> I am using DC1394_VIDEO1394_WAIT policy.
> The machine is Linux 2.6.32-24-generic #43-Ubuntu SMP Thu Sep 16 14:58:24
> UTC 2010 x86_64 GNU/Linux
> I am using OpenCV for grabbing frames.

It is reproducible using Coriander?

  -- Damien

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
Michael Joachimiak | 11 Oct 2010 22:59
Picon

Re: dropping frames. possible bug in libdc1394 ?

First of all sorry for the late response.

On the day you wrote the first response my first son was born and I took some days off.
Thank you Damien for interest.
1) I either set the shutter to about 30ms or use one-shot auto shutter. ( I am using Stingray F046C)
This is a good advice - I have to set it permanently to less than 66ms. But I don't think this is my problem. If the shutter time would be expanded I would get less frames per second. I don't see any reason why the latency would grow up to 1000ms? But maybe there is a reason?

2) I checked many different scenarios and it seems my code is ok. I tried POLL and WAIT policy. I run only image acquisition with writing without preview. Even one camera grabbing caused high latency after some time (this is weird).
I wrote a simple console application to avoid event loop processing and still the problem persists.

3) I think this is not the case since I measured times per frame and they were up to 40ms.

I have checked the coriander today and the latency was not growing. That's good. I can take a look at the source and write a libdc1394 based code.

Thank you for help.

2010/10/5 Damien Dusha <d.dusha-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Hello,

On Wed, Sep 22, 2010 at 6:10 PM, Michael Joachimiak
<mjoachimiak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> I am grabbing from 1394 IIDC cameras.
>
> From time to time I get very high latency - a bit more than 1s. The frames
> are dropped of course after that.
> How I can debug it more?
> My acquisition loop is not a problem - in the worst case it takes only 40ms
> per frame in 15Hz capturing.
> I am using DC1394_VIDEO1394_WAIT policy.
> The machine is Linux 2.6.32-24-generic #43-Ubuntu SMP Thu Sep 16 14:58:24
> UTC 2010 x86_64 GNU/Linux
> I am using OpenCV for grabbing frames.

It is reproducible using Coriander?

 -- Damien

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Mailing list for libdc1394-devel
libdc1394-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libdc1394-devel



--
Your Sincerely
Michael Joachimiak
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Mailing list for libdc1394-devel
libdc1394-devel@...
https://lists.sourceforge.net/lists/listinfo/libdc1394-devel
Michael Joachimiak | 12 Oct 2010 12:50
Picon

Re: dropping frames. possible bug in libdc1394 ?

I think I have found the problem.
I have somehow missed the problem of storing frames.
The cvWriteFrame time grows linearly, which finally causes slow frame read. Buffer overflows and frames are dropped. I measured the single frame processing time but at the beginning of the processing. After a while (maybe 5 mins) it grows because cvWriteFrame processing time grows.I have to ask opencv guys about this.
Below I post example code I have used for finding the problem.
Thank you Damien for help.

#include <QtCore/QCoreApplication> #include "highgui.h" #include <qfuture.h> #include <qtconcurrentrun.h> #include <qdatetime.h> CvCapture *capture_left,*capture_right; IplImage *frame_left,*frame_right; CvVideoWriter *writer_left; CvVideoWriter *writer_right; bool grabImage(int cameraidx) { //#ifdef OPENCV_CAPTURE if (cameraidx == 0) { // while(cvGrabFrame(capture_left) == 0) {} double t=(double)clock()/1000; bool ret; ret=cvGrabFrame(capture_left); t=(double)clock()/1000 - t; if (t>50) printf("Left waited %f ms\n",t); return ret; } if (cameraidx == 1) { //while(cvGrabFrame(capture_right)== 0) {} double t=(double)clock()/1000; bool ret; ret=cvGrabFrame(capture_right); t=(double)clock()/1000 - t; if (t>50) printf("Right waited %f ms\n",t); return ret; } //#endif return true; }//grabImage void clean() { cvReleaseCapture(&capture_left); cvReleaseCapture(&capture_right); //cvRelease(); cvDestroyAllWindows(); } int main(int argc, char *argv[]) { //provides event loop // QCoreApplication a(argc, argv); // a.exec(); CvSize imageSize; imageSize.width=640; imageSize.height=480; // capture_left = cvCaptureFromCAM(CV_CAP_IEEE1394 + 0); // capture_right = cvCaptureFromCAM(CV_CAP_IEEE1394 + 1); // cvReleaseCapture(&capture_left); // cvReleaseCapture(&capture_right); capture_left = cvCaptureFromCAM(CV_CAP_IEEE1394 + 0); capture_right = cvCaptureFromCAM(CV_CAP_IEEE1394 + 1); cvSetCaptureProperty(capture_left ,CV_CAP_PROP_FRAME_WIDTH,imageSize.width); cvSetCaptureProperty(capture_left ,CV_CAP_PROP_FRAME_HEIGHT,imageSize.height); //cvSetCaptureProperty(capture_left ,CV_CAP_PROP_FPS,3.75); //-- fps does not work for V4L2, works for FireWire cvSetCaptureProperty(capture_right ,CV_CAP_PROP_FRAME_WIDTH,imageSize.width); cvSetCaptureProperty(capture_right ,CV_CAP_PROP_FRAME_HEIGHT,imageSize.height); cvNamedWindow( "left"); cvNamedWindow( "right"); QFuture<bool> bleft=QtConcurrent::run(grabImage,0); QFuture<bool> bright=QtConcurrent::run(grabImage,1); // bool bleft=cvGrabFrame(capture_left); // bool bright=cvGrabFrame(capture_right); if (bleft) frame_left = cvRetrieveFrame(capture_left); if (bright) frame_right = cvRetrieveFrame(capture_right); QTime time = QTime::currentTime(); QString timeString = time.toString(); QString left=timeString+"left.yuv", right=timeString+"right.yuv"; // if (writer_left != NULL) // cvReleaseVideoWriter(&writer_left); // if (writer_right != NULL) // cvReleaseVideoWriter(&writer_right); writer_left = cvCreateVideoWriter(left.toAscii(),CV_FOURCC('I','4','2','0'),15,imageSize); writer_right = cvCreateVideoWriter(right.toAscii(),CV_FOURCC('I','4','2','0'),15,imageSize); char key; long count_l=0,count_r=0; for (;;) { if ((key=(char)cvWaitKey(5))!=-1) { clean(); exit(0); } // printf("Grabbing... "); bool bgrab_left = cvGrabFrame(capture_left); bool bgrab_right = cvGrabFrame(capture_right); //if (bgrab_left || bgrab_right) if (bgrab_left || bgrab_right) { double t=(double)clock();//CLOCKS_PER_SEC if (bgrab_left) { // printf("Grabbed LEFT"); count_l=0; frame_left = cvRetrieveFrame(capture_left); cvShowImage("left",frame_left); cvWriteFrame(writer_left,frame_left); } if (bgrab_right) { // printf("Grabbed RIGHT"); count_r=0; frame_right = cvRetrieveFrame(capture_right); cvShowImage("right",frame_right); cvWriteFrame(writer_right,frame_right); } printf("%s%d\n","CPU time used for storage: ",((double)clock()-t)/1000); // printf(", missed %d %d",count_l,count_r); // printf(" DONE\n"); } //else { // printf("%s","Two frames are missing\n\n\n"); // exit(1); // if (!bgrab_left) count_l++;//printf("%s","no LEFT"); // if (!bgrab_right) count_r++;//printf("%s","no RIGHT"); // //printf("\n"); // continue; // //exit(1); } }//for clean(); return 0; }

--
Your Sincerely
Michael Joachimiak
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Mailing list for libdc1394-devel
libdc1394-devel@...
https://lists.sourceforge.net/lists/listinfo/libdc1394-devel

Gmane