OpenCV 打开相机

/*
Copyright:
Author:Jeffrey 20210407
description: open cameras
instruction: 1.     g++ main.cpp `pkg-config opencv --cflags --libs` -o run          to compile
			 2.     ls /dev/video+tab                                                to query vedio No
			 3.     ./run No1 No2 ****                                               to open cameras
*/
#include 
#include
#define width 1280
#define height 720

using namespace cv;
using namespace std;

int camera_set(VideoCapture camera,int n,int width0,int height0);
int main(int argc,char *argv[])
{
    cout<<"| *-* please input No.(you can use [ls /dev/video+tab] to query) of video such as 0 *-* |"<<endl;
	for (int i =0;i<argc-1;++i)
	    printf("| ******* video %c will open *****|\n",argv[i+1][0]);


	VideoCapture camera0((argv[0+1][0])-48);
	Mat3b frame0;
	camera_set(camera0,0,width,height);

	while (true) {
		camera0 >> frame0;
		imshow(argv[1],frame0);
		int c = waitKey(2);
		if (27 == char(c)) break;
	}

	return 0;
}
int camera_set(VideoCapture camera,int n,int width0,int height0)
{
    camera.set(CAP_PROP_FRAME_WIDTH, width);
	camera.set(CAP_PROP_FRAME_HEIGHT, height);

	if (!camera.isOpened())
	   cout<<"|*******fail to open web camera ******|"<<n<<endl;
	else
	{
		cout<<"you have successfully open video "<<n<<endl;
	}

    return 0;
}

你可能感兴趣的:(opencv,c++,算法)