主题
打开摄像头并协商格式 - OpenCameraEx
函数简介
打开摄像头,并在首帧前协商像素大小、帧率和 FOURCC。device 可以是设备索引(如 "0")或友好名(如 "USB Camera"、OBS Virtual Camera)。
绑定前可用 EnumCameras 读取驱动报告的可选规格。实际像素大小以打开后的 GetVideoWidth / GetVideoHeight / GetVideoInfo 为准。
只要默认规格时,仍可用 OpenCamera 或 OpenCameraByName。
接口名称
OpenCameraExDLL调用
c
int64_t OpenCameraEx(int64_t instance, const char* device, int32_t width, int32_t height, double fps, const char* fourcc);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| device | 文本型 | 设备索引("0")或友好名("USB Camera")。空字符串按索引 0 打开。 |
| width | 整数型 | 请求像素宽。0 表示不指定,使用设备默认。 |
| height | 整数型 | 请求像素高。0 表示不指定,使用设备默认。 |
| fps | 双精度浮点数 | 请求帧率。0 表示不指定。 |
| fourcc | 文本型 | 请求像素格式,如 "MJPG"、"YUY2"、"NV12"。空字符串表示不指定。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG");csharp
using OLAPlug;
var ola = new OLAPlugServer();
long handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
handle := ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG")rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let handle = ola.open_camera_ex("0", 1920, 1080, 30.0, "MJPG");cpp
var ola = com("OlaPlug.OlaSoft")
var handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG")text
.局部变量 ola, OLAPlug
ola.创建 ()
handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG")aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long handle = ola.OpenCameraEx("0", 1920, 1080, 30.0, "MJPG");原生 DLL 调用
cpp
OpenCameraEx(instance, "0", 1920, 1080, 30.0, "MJPG");csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long OpenCameraEx(long ola, string device, int width, int height, double fps, string fourcc);
OpenCameraEx(instance, "0", 1920, 1080, 30.0, "MJPG");python
from ctypes import CDLL, c_int, c_int64, c_double, c_char_p
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.OpenCameraEx.restype = c_int64
ola.OpenCameraEx.argtypes = [c_int64, c_char_p, c_int, c_int, c_double, c_char_p]
ola.OpenCameraEx(instance, b"0", 1920, 1080, 30.0, b"MJPG")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 长整数型:视频句柄,失败返回 0。 |
注意事项
| 项目 | 说明 |
|---|---|
| 实际像素大小 | 设备可能协商出与请求不同的宽高。打开后用 GetVideoWidth / GetVideoHeight / GetVideoInfo 的 actual 读取。 |
| 改格式 | 已打开的句柄可用 SetCameraFormat 修改。多数 USB 设备改分辨率会重开设备。 |
| 释放 | 返回的句柄用于后续视频操作,使用完毕后调用 CloseVideo。 |
| 占用 | 确保目标设备已连接且未被其他程序独占。 |
| 绑定图色 | 要把摄像头当作截图源(Capture / FindPic),用 BindWindowEx 的 display="camera",参数走 SetConfig 的 Camera*,与本接口的视频句柄相互独立。 |
