#pragma execution_character_set("utf-8") #include <opencv2/opencv.hpp> #include <opencv2/core/core.hpp> int main() { cv::VideoCapture capDevice(0); capDevice.open(0); //设置摄像头采集图像分辨率 capDevice.set(cv::CAP_PROP_FRAME_WIDTH, 1024.0); capDevice.set(cv::CAP_PROP_FRAME_HEIGHT, 960.0); capDevice.set(cv::CAP_PROP_FRAME_WIDTH, 1080);//宽度 capDevice.set(cv::CAP_PROP_FRAME_HEIGHT, 960);//高度 //capDevice.set(cv::CAP_PROP_FPS, 30);//帧率 帧/秒 capDevice.set(cv::CAP_PROP_BRIGHTNESS, 1);//亮度 1 capDevice.set(cv::CAP_PROP_CONTRAST, 60);//对比度 40 capDevice.set(cv::CAP_PROP_SATURATION, 64);//饱和度 50 capDevice.set(cv::CAP_PROP_HUE, 0);//色调 capDevice.set(cv::CAP_PROP_EXPOSURE, -7);//曝光 50 cv::Mat srcImage; //宽度 double width = capDevice.get(cv::CAP_PROP_FRAME_WIDTH); //高度 double height = capDevice.get(cv::CAP_PROP_FRAME_HEIGHT); //帧率 帧/秒 //int fps = capDevice.get(cv::CAP_PROP_FPS); //亮度 double bright = capDevice.get(cv::CAP_PROP_BRIGHTNESS); //对比度 double contrast = capDevice.get(cv::CAP_PROP_CONTRAST); //饱和度 double saturation = capDevice.get(cv::CAP_PROP_SATURATION); //色调 double hue = capDevice.get(cv::CAP_PROP_HUE); //曝光时长 double exposure = capDevice.get(cv::CAP_PROP_EXPOSURE); //设置绘制文本的相关参数 char text[255] = ""; int font_face = cv::FONT_HERSHEY_COMPLEX; double font_scale = 1; int thickness = 1; while (true) { if (capDevice.isOpened()) { capDevice >> srcImage; } sprintf(text, "%0.1f height:%0.1f exposure:%0.1f", width, height, exposure); cv::putText(srcImage, text, cv::Point(20, 30), font_face, font_scale, cv::Scalar(0, 255, 255), thickness, 8, 0); sprintf(text, "bright:%0.1f contrast:%0.1f saturation:%0.1f hue:%0.1f", bright, contrast, saturation, hue); cv::putText(srcImage, text, cv::Point(20, 90), font_face, font_scale, cv::Scalar(0, 255, 255), thickness, 8, 0); imshow("image", srcImage); cv::waitKey(30); } }