23

WindowsでopenCV 1.1pre1を使用しています。ネットワーク カメラがあり、openCV からフレームを取得する必要があります。そのカメラは、RTSP 経由で標準の mpeg4 ストリームをストリーミングしたり、http 経由で mjpeg をストリーミングしたりできます。openCV で ffmpeg を使用することについて話している多くのスレッドを見てきましたが、それを機能させることはできません。

openCV を使用して IP カメラからフレームを取得するにはどうすればよいですか?

ありがとう

アンドレア

4

6 に答える 6

23

フレームを取得するためのC++コードを同封しました。OpenCVバージョン2.0以降が必要です。このコードは、古いIplImage構造よりも優先されるcv::mat構造を使用しています。

#include "cv.h"
#include "highgui.h"
#include <iostream>

int main(int, char**) {
    cv::VideoCapture vcap;
    cv::Mat image;

    const std::string videoStreamAddress = "rtsp://cam_address:554/live.sdp"; 
    /* it may be an address of an mjpeg stream, 
    e.g. "http://user:pass@cam_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" */

    //open the video stream and make sure it's opened
    if(!vcap.open(videoStreamAddress)) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }

    //Create output window for displaying frames. 
    //It's important to create this window outside of the `for` loop
    //Otherwise this window will be created automatically each time you call
    //`imshow(...)`, which is very inefficient. 
    cv::namedWindow("Output Window");

    for(;;) {
        if(!vcap.read(image)) {
            std::cout << "No frame" << std::endl;
            cv::waitKey();
        }
        cv::imshow("Output Window", image);
        if(cv::waitKey(1) >= 0) break;
    }   
}

更新H.264RTSPストリームからフレームを取得できます。URLコマンドを取得するための詳細については、カメラAPIを検索してください。たとえば、Axisネットワークカメラの場合、URLアドレスは次のようになります。

// H.264 stream RTSP address, where 10.10.10.10 is an IP address 
// and 554 is the port number
rtsp://10.10.10.10:554/axis-media/media.amp

// if the camera is password protected
rtsp://username:password@10.10.10.10:554/axis-media/media.amp
于 2012-01-03T21:57:37.787 に答える
10
#include <stdio.h>
#include "opencv.hpp"


int main(){

    CvCapture *camera=cvCaptureFromFile("http://username:pass@cam_address/axis-cgi/mjpg/video.cgi?resolution=640x480&req_fps=30&.mjpg");
    if (camera==NULL)
        printf("camera is null\n");
    else
        printf("camera is not null");

    cvNamedWindow("img");
    while (cvWaitKey(10)!=atoi("q")){
        double t1=(double)cvGetTickCount();
        IplImage *img=cvQueryFrame(camera);
        double t2=(double)cvGetTickCount();
        printf("time: %gms  fps: %.2g\n",(t2-t1)/(cvGetTickFrequency()*1000.), 1000./((t2-t1)/(cvGetTickFrequency()*1000.)));
        cvShowImage("img",img);
    }
    cvReleaseCapture(&camera);
}
于 2011-05-20T11:11:54.937 に答える
5

OpenCVはFFMPEGをサポートしてコンパイルできます。./configure --helpから:

--with-ffmpeg     use ffmpeg libraries (see LICENSE) [automatic]

次に、 cvCreateFileCapture_FFMPEGを使用して、カメラのMJPGストリームのURLなどを使用してCvCaptureを作成できます。

これを使用して、AXISカメラからフレームを取得します。

CvCapture *capture = 
    cvCreateFileCapture_FFMPEG("http://axis-cam/mjpg/video.mjpg?resolution=640x480&req_fps=10&.mjpg");
于 2009-06-18T14:28:02.787 に答える
3

rtsp プロトコルが機能しませんでした。mjpegは最初の試行で機能しました。私のカメラ(Dlink DCS 900)に組み込まれていると思います。

ここにある構文: http://answers.opencv.org/question/133/how-do-i-access-an-ip-camera/

ffmpg をサポートする OpenCV をコンパイルする必要はありませんでした。

于 2012-11-28T22:21:00.973 に答える
3

私はちょうどこのようにそれを行います:

CvCapture *capture = cvCreateFileCapture("rtsp://camera-address");

また、この dll が実行時に利用可能であることを確認してください。そうでない場合、cvCreateFileCapture は NULL を返します。

opencv_ffmpeg200d.dll

カメラは認証されていないアクセスも許可する必要があり、通常は Web インターフェースを介して設定されます。MJPEG 形式は rtsp 経由で機能しましたが、MPEG4 は機能しませんでした。

h番目

于 2010-02-11T11:48:15.187 に答える
1

ffmpeglib を使用してストリームに接続します。

これらの関数が役立つ場合があります。しかし、ドキュメントを見てください

av_open_input_stream(...);
av_find_stream_info(...);
avcodec_find_decoder(...);
avcodec_open(...);
avcodec_alloc_frame(...);

ここで入手できる完全なフレームを取得するには、少しアルゴリズムが必要です。

http://www.dranger.com/ffmpeg/tutorial01.html

Once you get a frame you could copy the video data (for each plane if needed) into a IplImage which is an OpenCV image object.

You can create an IplImage using something like...

IplImage *p_gray_image = cvCreateImage(size, IPL_DEPTH_8U, 1);

Once you have an IplImage, you could perform all sorts of image operations available in the OpenCV lib

于 2009-04-03T09:31:07.800 に答える