带有网络摄像机的OpenCV

我在Windows下使用openCV 1.1pre1。我有一个网络摄像机,我需要从openCV抓取帧。该摄像机可以通过RTSP传输标准mpeg4流,或通过http传输mjpeg。我已经看到很多线程都在谈论将ffmpeg与openCV一起使用,但是我无法使其正常工作。


如何使用openCV从IP摄像机抓取帧?


万千封印
浏览 517回答 3
3回答

潇湘沐

#include <stdio.h>#include "opencv.hpp"int main(){&nbsp; &nbsp; CvCapture *camera=cvCaptureFromFile("http://username:pass@cam_address/axis-cgi/mjpg/video.cgi?resolution=640x480&req_fps=30&.mjpg");&nbsp; &nbsp; if (camera==NULL)&nbsp; &nbsp; &nbsp; &nbsp; printf("camera is null\n");&nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; printf("camera is not null");&nbsp; &nbsp; cvNamedWindow("img");&nbsp; &nbsp; while (cvWaitKey(10)!=atoi("q")){&nbsp; &nbsp; &nbsp; &nbsp; double t1=(double)cvGetTickCount();&nbsp; &nbsp; &nbsp; &nbsp; IplImage *img=cvQueryFrame(camera);&nbsp; &nbsp; &nbsp; &nbsp; double t2=(double)cvGetTickCount();&nbsp; &nbsp; &nbsp; &nbsp; printf("time: %gms&nbsp; fps: %.2g\n",(t2-t1)/(cvGetTickFrequency()*1000.), 1000./((t2-t1)/(cvGetTickFrequency()*1000.)));&nbsp; &nbsp; &nbsp; &nbsp; cvShowImage("img",img);&nbsp; &nbsp; }&nbsp; &nbsp; cvReleaseCapture(&camera);}
打开App,查看更多内容
随时随地看视频慕课网APP