设置摄像头分辨率

一、videocapture类的介绍

1、Class for video capturing from video files, image sequences or cameras.

2、The class provides C++ API for capturing video from cameras or for reading video files and image sequences.


二、参数设置函数 set() 函数的使用

1、代码

//
#include "cartoon.h"  
  
int main()  
{  
    VideoCapture capture(0);  
    if (!capture.isOpened()) { //判断能够打开摄像头  
        cout<<"can not open the camera"<<endl;  
        cin.get();  
        exit(1);  
    }  
  
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);  
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);  
  
    int count=0;  
  
    while (1) {  
        Mat frame;  
        capture>>frame; //载入图像  
  
        if (frame.empty()) { //判断图像是否载入  
            cout<<"can not load the frame"<<endl;  
        } else {  
            count++;  
            if (count == 1) {  
                cout<<frame.cols<<"  "<<frame.rows<<endl;  
            }  
  
            imshow("camera", frame);  
            char c=waitKey(30); //延时30毫秒  
            if (c == 27) //按ESC键退出  
                break;  
        }  
    }  
}  
//


致谢

1、videocapture官方介绍


### C# 中使用 OpenCV 设置摄像头分辨率 为了在 C# 中使用 OpenCV 库来设置摄像头分辨率,通常会借助 Emgu CV 这个封装库。Emgu CV 是 OpenCV 的 .NET 封装版本,提供了更方便的操作接口。 下面是一个简单的例子展示如何设置摄像头分辨率为 1280x720: ```csharp using System; using Emgu.CV; using Emgu.CV.CvEnum; using Emgu.CV.Structure; class Program { static void Main(string[] args) { Capture capture = new Capture(); // Set camera properties using SetProperty method. // Check if the property can be set successfully by verifying the return value. double resultWidth = capture.SetCaptureProperty(CapProp.FrameWidth, 1280); double resultHeight = capture.SetCaptureProperty(CapProp.FrameHeight, 720); Console.WriteLine($"Set Width Result: {resultWidth}, Expected: 1280"); Console.WriteLine($"Set Height Result: {resultHeight}, Expected: 720"); Mat frame = new Mat(); while (true) { try { capture.Read(frame); // Read a new frame from video source if (!frame.IsEmpty()) { CvInvoke.Imshow("Camera", frame); // Display the frame in window named "Camera" // Break loop when ESC key pressed if (((int)CvInvoke.WaitKey(10)) == 27) break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } CvInvoke.DestroyAllWindows(); // Destroy all windows before exiting program capture.Dispose(); // Release resources used by VideoCapture object } } ``` 这段代码创建了一个 `Capture` 对象用于访问默认摄像设备,并尝试将其帧宽度和高度分别设为 1280 和 720 像素。需要注意的是并非所有的硬件都支持任意尺寸的调整;具体取决于所使用的摄像头型号及其驱动的支持情况[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

worthsen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值