这是用于使用lan端口访问我的IP摄像机的代码。(第一个代码工作正常)。我需要的是获得垫(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;
}Exception : Hog with Web cam.exe中0x00660598处的未处理异常: 0xC0000005:访问冲突读取位置0xcccc0065。
发布于 2014-03-14 17:27:41
是的,去掉那该死的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;
}https://stackoverflow.com/questions/22400324
复制相似问题