opencv-3.1.0+vs2015+海思网络摄像头

测试很多代码,只有此版本通过,估计是每个版本对应方法不同

 

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

}
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值