C++ 使用rtsp、visual studio OpenCv 2.4.5访问IP摄像头?

C++ 使用rtsp、visual studio OpenCv 2.4.5访问IP摄像头?,c++,c,visual-c++,opencv,image-processing,C++,C,Visual C++,Opencv,Image Processing,这是用于使用lan端口访问我的IP摄像头的代码。(第一个代码可以正常工作)。我需要的是得到Mat(C++)结构的图像。代码2显示了我使用Mat结构所做的工作,但是当我调试程序时,执行cv::namedWindow(“Frame”);然后中断代码,发出一个未处理的异常,如下所示。 我的最终要求是使用Mat而不是iplimage完成这项工作。提示或适当的代码将是伟大的,因为我正在做一个项目,人类检测使用猪。谢谢 #include "stdafx.h" #include <stdio.h>

这是用于使用lan端口访问我的IP摄像头的代码。(第一个代码可以正常工作)。我需要的是得到Mat(C++)结构的图像。代码2显示了我使用Mat结构所做的工作,但是当我调试程序时,执行cv::namedWindow(“Frame”);然后中断代码,发出一个未处理的异常,如下所示。 我的最终要求是使用Mat而不是iplimage完成这项工作。提示或适当的代码将是伟大的,因为我正在做一个项目,人类检测使用猪。谢谢

#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);
}
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括“opencv.hpp”
int main(){

CvCapture*camera=cvCaptureFromFile(“rtsp://192.168.1.19:554/0/1:1/main"); 如果(摄像机==NULL) printf(“照相机为空\n”); 其他的 printf(“摄像机不为空”); CVD公司(“img”); while(cvWaitKey(10)!=atoi(“q”)){ IplImage*img=cvQueryFrame(摄像机); cvShowImage(“img”,img); } cvReleaseCapture(相机和相机); }
代码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;
}
intmain(intargc,char*argv[])
{

cv::Ptr capture=cvCaptureFromFile(“rtsp://192.168.1.19:554/0/1:1/main"); cv::namedWindow(“框架”); 对于(;;) { cv::Mat frame=cvQueryFrame(捕获); cv::imshow(“帧”,帧); 如果(cv::waitKey(1)>=0) 打破 } 返回0; }
例外情况:
Web cam.exe为0xC0000005的Hog中0x00660598处的未处理异常:访问冲突读取位置0xCC0065

是的,摆脱该死的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;
}

"rtsp://192.168.1.19:554/0/1:1/main“这是我的ip地址和密码保护。这是从相机的用户手册中获取的。显然,它是为了在vlc中传输rtsp,以便将其与cv::VideoCapture vcap一起使用;我是否需要更改格式或添加虚拟尾部?任何提示谢谢。因为我已经用这个代码试过了,它不会从相机上捕获任何帧。摄像头似乎为空。您是否尝试将opencv_ffmpeg248.dll放置在输出目录中?