openCV 打开摄像头

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013420428/article/details/82748176
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"

#include <iostream>


using namespace std;
using namespace cv;

void drawText(Mat & image);

int main(int argc, char **argv)
{
    cout << "Built with OpenCV" << CV_VERSION << endl;
    Mat image;
    VideoCapture capture;
    capture.open(0);
    
    if (capture.isOpened())
    {
        cout << "Capture is opend" << endl;
        for(;;)
        {
            capture >> image;
            if (image.empty())
                break;
            drawText(image);
            imshow("Camera", image);
            if (waitKey(10) >= 0) {
                break;
            }
        }
    }
    else
    {
        cout << "No capture"<< endl;
        image = Mat::zeros(480, 640, CV_8UC1);
        drawText(image);
        imshow("Camera", image);
        waitKey(0);
    }
    return 0;
}

void drawText(Mat & image)
{
    putText(image, "Good Day!",
            Point(10, 30),
            FONT_HERSHEY_COMPLEX, 1,// font face and scale
            Scalar(255, 255, 255),// white
            1, LINE_AA);// line thickness and type
}

猜你喜欢

转载自blog.csdn.net/u013420428/article/details/82748176