本例程功能捕获本地摄像头图像,转换格式并显示。
#include<iostream>
#include<opencv2/highgui.hpp>
#include<opencv2/imgcodecs.hpp>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
void main(int argc, char** argv)
{
VideoCapture mVideoCap(0);
Mat capMat;
Mat gray, HSV, YUV, Lab, img32;
while (1)
{
mVideoCap.read(capMat);
if (!capMat.empty())
{
capMat.convertTo(img32,CV_32F,1.0/255);
cvtColor(img32,HSV,COLOR_BGR2HSV);
cvtColor(img32, YUV, COLOR_BGR2YUV);
cvtColor(img32, Lab, COLOR_BGR2Lab);
cvtColor(img32, gray, COLOR_BGR2GRAY);
imshow("img32", img32);
imshow("HSV", HSV);
imshow("YUV", YUV);
imshow("Lab", Lab);
imshow("gray", gray);
waitKey(1);
}
}
return ;
}