簡體   English   中英

使用rtsp,Visual Studio OpenCv 2.4.5訪問IP攝像機?

[英]IP camera acessing using rtsp, visual studio OpenCv 2.4.5?

這是用於通過lan端口訪問我的IP攝像機的代碼。 (第一個代碼工作正常)。 我需要的是獲取具有Mat(C ++)結構的圖像。 代碼2顯示了我使用Mat結構所做的事情,但是當我調試程序時,執行cv :: namedWindow(“ Frame”); 然后破壞代碼,給出未處理的異常,顯示波紋管。 我的最終要求是使用Mat而不是iplimage完成這項工作。 提示或適當的代碼將非常有用,因為我正在做一個有關使用HOG進行人體檢測的項目。 謝謝。

#include "stdafx.h"
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include "opencv.hpp"

int main(){

CvCapture *camera=cvCaptureFromFile("rtsp://192.168.1.19:554/0/1:1/main");
if (camera==NULL)
printf("camera is null\n");
else
printf("camera is not null");

cvNamedWindow("img");
while (cvWaitKey(10)!=atoi("q")){

IplImage *img=cvQueryFrame(camera);
cvShowImage("img",img);
}
cvReleaseCapture(&camera);
}

代碼2:

int main(int argc, char* argv[])
{
        cv::Ptr<CvCapture> capture = cvCaptureFromFile("rtsp://192.168.1.19:554/0/1:1/main");
        cv::namedWindow("Frame");
        for (;;)
        {
            cv::Mat frame = cvQueryFrame(capture);
            cv::imshow("Frame", frame);
            if (cv::waitKey(1) >= 0)
            break;
        }
    return 0;
}

異常:帶有Web cam.exe的Hog中0x00660598的未處理異常:0xC0000005:訪問沖突讀取位置0xcccc0065。

是的,擺脫該死的c-api!

int main(int argc, char* argv[])
{
        cv::namedWindow("Frame");
        cv::VideoCapture capture("rtsp://192.168.1.19:554/0/1:1/main");
        while ( capture.isOpened() )     // check !!
        {
            cv::Mat frame;
            if ( ! capture.read(frame) ) // another check !!
                break;

            cv::imshow("Frame", frame);
            if (cv::waitKey(1) >= 0)
                break;
        }
    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM