简体   繁体   English

使用rtsp,Visual Studio OpenCv 2.4.5访问IP摄像机?

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

This is the code used to access my IP camera using lan port. 这是用于通过lan端口访问我的IP摄像机的代码。 (first code works fine). (第一个代码工作正常)。 What I need is to get image with Mat(C++) structure. 我需要的是获取具有Mat(C ++)结构的图像。 Code number 2 shows what I have done to using Mat structure but when I debug the program, execute cv::namedWindow("Frame"); 代码2显示了我使用Mat结构所做的事情,但是当我调试程序时,执行cv :: namedWindow(“ Frame”); and then breaks the code giving out an Unhandled exception which shows bellow. 然后破坏代码,给出未处理的异常,显示波纹管。 My Final requirement is to get this job done using Mat instead of iplimage. 我的最终要求是使用Mat而不是iplimage完成这项工作。 tip or an appropriate code would be great since I am doing a project on Human detection using HOG. 提示或适当的代码将非常有用,因为我正在做一个有关使用HOG进行人体检测的项目。 thanks. 谢谢。

#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);
}

code number 2 : 代码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;
}

Exception : Unhandled exception at 0x00660598 in Hog with Web cam.exe: 0xC0000005: Access violation reading location 0xcccc0065. 异常:带有Web cam.exe的Hog中0x00660598的未处理异常:0xC0000005:访问冲突读取位置0xcccc0065。

yea, get rid of the darn c-api ! 是的,摆脱该死的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