yanjinhui
2025-06-12 95ac5296182b763d12125c1d47f53c00632ffc41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
 
namespace WIDESEAWCS_Common.Face
{
    // 相机取帧及帧图象显示组件
    public class CHS_Capture
    {
        // 返回相机个数
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraGetCount", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int SmCameraGetCount();
 
        // 打开相机(根据相机索引号 nDeviceId)
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraOpen", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr SmCameraOpen(int nDeviceId, int nWidth, int nHeight);
 
        // 打开相机(根据相机VID+PIC)
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraOpenEx", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr SmCameraOpenEx(int nVid, int nPid, int nWidth, int nHeight);
 
        // 从打开的相机提取一帧视频数据
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraGetFrame", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int SmCameraGetFrame(IntPtr hCamera, IntPtr pFrameBuf, int bMirror, int bFlip);
 
        // 关闭相机
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraClose", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern void SmCameraClose(IntPtr hCamera);
 
        // 创建视频帧显示对象(nWidth * nHeight 为视频帧的分辨率,hWnd 为显示窗口句柄)
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraPreviewCreate", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr SmCameraPreviewCreate(int nWidth, int nHeight, IntPtr hWND);
 
        // 显示视频帧
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraPreview", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern void SmCameraPreview(IntPtr hCameraPreview, IntPtr pFrame);
 
        // 显示视频帧及人脸框(weight为边框的厚度)
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraPreviewFace", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern void SmCameraPreviewFace(IntPtr hCameraPreview, IntPtr pFrame, int left, int top, int right, int bottom, int weight, int color);
 
        // 释放视频帧显示对象
        [DllImport("SmCameraPreview.dll", EntryPoint = "SmCameraPreviewDestroy", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern void SmCameraPreviewDestroy(IntPtr hCameraPreivew);
    }
}