开发者

Read an image in specified interval with OpenCV

开发者 https://www.devze.com 2023-03-28 06:30 出处:网络
There is a file on 开发者_如何学JAVAthe network and it will be refreshed every 50 millisecond, I want to read it every 50ms, it\'s my code:

There is a file on 开发者_如何学JAVAthe network and it will be refreshed every 50 millisecond, I want to read it every 50ms, it's my code:

int main(int argc, char* argv[])
{
int c;
    IplImage *img;
    CvCapture* capture = cvCaptureFromFile("http://192.168.1.3:8020/image.jpg");
    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
    cvMoveWindow("mainWin", 5, 5);
    while(1)
    {
        img=cvQueryFrame(capture);
        cvShowImage("mainWin", img );
        c=cvWaitKey(10);
        if(c == 27)
        break;
    }
 return 0;

}

but this code read it once.


cvCaptureFromFile is for readign from video files, if you pass it a single image it assumes it can't change so always returns the same image

I don't know if cvLoadImage will read from a URL in your version of openCV but try:

cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 5, 5);
while(1)
{
    CvCapture* capture = cvCaptureFromFile("http://192.168.1.3:8020/image.jpg");
    img=cvQueryFrame(capture);
    cvShowImage("mainWin", img );
    c=cvWaitKey(10);
    cvReleaseCapture(&capture);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消