2014-03-14 71 views
1

这是用于使用LAN端口访问我的IP摄像头的代码。 (第一个代码工作正常)。我需要的是用Mat(C++)结构获取图像。代码2显示了我使用Mat结构做了些什么,但是当我调试程序时,执行cv :: namedWindow(“Frame”);然后打破显示波纹管的未处理异常的代码。 我最后的要求是使用Mat而不是iplimage完成这项工作。提示或适当的代码会很好,因为我正在使用HOG进行人体检测项目。谢谢。IP摄像机使用rtsp,视觉工作室OpenCv 2.4.5?

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

例外: 在0x00660598未处理的异常生猪与网络cam.exe:0000005:访问冲突读取位置0xcccc0065。

回答

0

是的,摆脱困扰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; 
} 
+0

“rtsp://192.168.1.19:554/0/1:1/main”这是我的IP地址,并且它的密码被保护。这是从相机的用户手册中提取的。显然它被赋予流在vlc中的rtsp,所以用于cv :: VideoCapture vcap;我是否需要更改格式或添加虚拟尾部?任何提示谢谢。 – OmegaD

+0

因为我已经尝试过使用这段代码,它并没有从相机捕获任何帧。相机似乎是空的。 – OmegaD

+0

您是否尝试将opencv_ffmpeg248.dll放入您的输出目录? – Naren