繁体   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