测试很多代码,只有此版本通过,估计是每个版本对应方法不同
/*#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
int main(int argc, char** argv)
{
String rtsp_addr = "rtsp://admin:a1234567@192.168.1.88:554/MPEG-4/ch1/main/av_stream";
VideoCapture cap(rtsp_addr);
// cap.open(rtsp_addr);
Mat frame;
for (;;) {
cap >> frame;
if (frame.empty())
break;
imshow("Video Stream", frame);
if (waitKey(10) == 'q')
break;
}
}
*/
/*
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap;
if (argc > 1)
cap.open(argv[1]);
else
cap.open(0);
if (!cap.isOpened())
{
std::cerr << "Cannot read video. Try moving video file to sample directory." << std::endl;
return -1;
}
namedWindow("FG Segmentation", WINDOW_NORMAL);
for (;;)
{
cap >> frame;
if (frame.empty())
break;
frame.copyTo(segm);
imshow("FG Segmentation", segm);
int c = waitKey(30);
if (c == 'q' || c == 'Q' || (c & 255) == 27)
break;
}
return 0;
m_videoCapture.open(1);//启动外置摄像头
if (false == m_videoCapture.isOpen())
{
AfxMessageBox("摄像头启动失败!");
return -1;
}
///设置摄像头分辨率
m_videoCapture.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
m_videoCapture.set(CV_CAP_PROP_FRAME_HEIGHT, 960);
Mat img;
while(1)
{
m_videoCapture.read(img);//抓取每一帧图像到Mat
if (img.isEmpty())
{
AfxMessageBox("图像为空!");
continue;
}
cv::imshow("img",img);
cv::waitKey(10);
}
m_videoCapture.release();
} */
/*出窗口 摄像头灯亮, 但是灰色无图像,
#include <opencv.hpp>
using namespace cv;
int main(int argc, char** argv)
{
cvNamedWindow("视频");
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while (1)
{
frame = cvQueryFrame(capture);
cvResizeWindow("视频", 640, 480);
cvShowImage("视频", frame);
cvWaitKey(50);
}
cvReleaseCapture(&capture);
cvDestroyWindow("视频");
return 0;
}
*/
/* 测试成功
#include <opencv.hpp>
using namespace cv;
int main() {
VideoCapture capture(0);
if (!capture.isOpened())
return -1;
Mat frame;
while (1) {
capture >> frame;
imshow("读取视频", frame);
waitKey(30);
}
return 0;
}*/
/* 测试成功
#include <opencv.hpp>
using namespace cv;
int main() {
VideoCapture capture(1);//VideoCapture capture(0);
if (!capture.isOpened())
return -1;
Mat frame;
while (1) {
capture >> frame;
imshow("读取视频", frame);
waitKey(30);
}
return 0;
}
*/
/*成功
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string videoStreamAddress = "rtsp://192.168.1.88/11";//测试"rtsp://192.168.1.88/80";失败,此端口可以用海思测试软件查看
//const std::string videoStreamAddress = "rtsp://192.168.1.100:554/ch1/1";
/* it may be an address of an mjpeg stream,
e.g. "http://user:pass@cam_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" */
//open the video stream and make sure it's opened
/*if (!vcap.open(videoStreamAddress)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
cv::namedWindow("Output Window");
for (;;) {
if (!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if (cv::waitKey(1) >= 0) break;
}
}
*/
/*失败 rtsp://192.168.1.88/11 rtsp://192.168.1.88/80 */
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string videoStreamAddress = "rtsp://192.168.1.88/80";
//const std::string videoStreamAddress = "rtsp://192.168.1.100:554/ch1/1";
/* it may be an address of an mjpeg stream,
e.g. "http://user:pass@cam_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" */
//open the video stream and make sure it's opened
if (!vcap.open(videoStreamAddress)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
cv::namedWindow("Output Window");
for (;;) {
if (!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if (cv::waitKey(1) >= 0) break;
}
}