Commit 600adfe0 by 范立洲

add gitignore

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
# vscode
.vscode/
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# \~chinese 设备类型定义 \~english Device Type Definition
MV_UNKNOW_DEVICE = 0x00000000 # < \~chinese 未知设备类型,保留意义 \~english Unknown Device Type, Reserved
MV_GIGE_DEVICE = 0x00000001 # < \~chinese GigE设备 \~english GigE Device
MV_1394_DEVICE = 0x00000002 # < \~chinese 1394-a/b 设备 \~english 1394-a/b Device
MV_USB_DEVICE = 0x00000004 # < \~chinese USB 设备 \~english USB Device
MV_CAMERALINK_DEVICE = 0x00000008 # < \~chinese CameraLink设备 \~english CameraLink Device
INFO_MAX_BUFFER_SIZE = 64 # < \~chinese 最大的数据信息大小 \~english Maximum data information size
MV_MAX_TLS_NUM = 8 # < \~chinese 最多支持的传输层实例个数 \~english The maximum number of supported transport layer instances
MV_MAX_DEVICE_NUM = 256 # < \~chinese 最大支持的设备个数 \~english The maximum number of supported devices
MV_MAX_GENTL_IF_NUM = 256 # < \~chinese 最大支持的GenTL数量 \~english The maximum number of GenTL supported
MV_MAX_GENTL_DEV_NUM = 256 # < \~chinese 最大支持的GenTL设备数量 \~english The maximum number of GenTL devices supported
# \~chinese 设备的访问模式 \~english Device Access Mode
# \~chinese 独占权限,其他APP只允许读CCP寄存器 \~english Exclusive authority, other APP is only allowed to read the CCP register
MV_ACCESS_Exclusive = 1
# \~chinese 可以从5模式下抢占权限,然后以独占权限打开 \~english You can seize the authority from the 5 mode, and then open with exclusive authority
MV_ACCESS_ExclusiveWithSwitch = 2
# \~chinese 控制权限,其他APP允许读所有寄存器 \~english Control authority, allows other APP reading all registers
MV_ACCESS_Control = 3
# \~chinese 可以从5的模式下抢占权限,然后以控制权限打开 \~english You can seize the authority from the 5 mode, and then open with control authority
MV_ACCESS_ControlWithSwitch = 4
# \~chinese 以可被抢占的控制权限打开 \~english Open with seized control authority
MV_ACCESS_ControlSwitchEnable = 5
# \~chinese 可以从5的模式下抢占权限,然后以可被抢占的控制权限打开 \~english You can seize the authority from the 5 mode, and then open with seized control authority
MV_ACCESS_ControlSwitchEnableWithKey = 6
# \~chinese 读模式打开设备,适用于控制权限下 \~english Open with read mode and is available under control authority
MV_ACCESS_Monitor = 7
MV_MATCH_TYPE_NET_DETECT = 0x00000001 # < \~chinese 网络流量和丢包信息 \~english Network traffic and packet loss information
MV_MATCH_TYPE_USB_DETECT = 0x00000002 # < \~chinese host接收到来自U3V设备的字节总数 \~english The total number of bytes host received from U3V device
# \~chinese GigEVision IP配置 \~english GigEVision IP Configuration
MV_IP_CFG_STATIC = 0x05000000 # < \~chinese 静态 \~english Static
MV_IP_CFG_DHCP = 0x06000000 # < \~chinese DHCP \~english DHCP
MV_IP_CFG_LLA = 0x04000000 # < \~chinese LLA \~english LLA
# \~chinese GigEVision网络传输模式 \~english GigEVision Net Transfer Mode
MV_NET_TRANS_DRIVER = 0x00000001 # < \~chinese 驱动 \~english Driver
MV_NET_TRANS_SOCKET = 0x00000002 # < \~chinese Socket \~english Socket
# \~chinese CameraLink波特率 \~english CameraLink Baud Rates (CLUINT32)
MV_CAML_BAUDRATE_9600 = 0x00000001 # < \~chinese 9600 \~english 9600
MV_CAML_BAUDRATE_19200 = 0x00000002 # < \~chinese 19200 \~english 19200
MV_CAML_BAUDRATE_38400 = 0x00000004 # < \~chinese 38400 \~english 38400
MV_CAML_BAUDRATE_57600 = 0x00000008 # < \~chinese 57600 \~english 57600
MV_CAML_BAUDRATE_115200 = 0x00000010 # < \~chinese 115200 \~english 115200
MV_CAML_BAUDRATE_230400 = 0x00000020 # < \~chinese 230400 \~english 230400
MV_CAML_BAUDRATE_460800 = 0x00000040 # < \~chinese 460800 \~english 460800
MV_CAML_BAUDRATE_921600 = 0x00000080 # < \~chinese 921600 \~english 921600
MV_CAML_BAUDRATE_AUTOMAX = 0x40000000 # < \~chinese 最大值 \~english Auto Max
# \~chinese 异常消息类型 \~english Exception message type
MV_EXCEPTION_DEV_DISCONNECT = 0x00008001 # < \~chinese 设备断开连接 \~english The device is disconnected
MV_EXCEPTION_VERSION_CHECK = 0x00008002 # < \~chinese SDK与驱动版本不匹配 \~english SDK does not match the driver version
MAX_EVENT_NAME_SIZE = 128 # < \~chinese 设备Event事件名称最大长度 \~english Max length of event name
MV_MAX_XML_SYMBOLIC_NUM = 64 # \~chinese 最大XML符号数 \~english Max XML Symbolic Number
#!/usr/bin/env python
# -*- coding: utf-8 -*-
MV_OK = 0x00000000 # < \~chinese 成功,无错误 \~english Successed, no error
# 通用错误码定义:范围0x80000000-0x800000FF
MV_E_HANDLE = 0x80000000 # < \~chinese 错误或无效的句柄 \~english Error or invalid handle
MV_E_SUPPORT = 0x80000001 # < \~chinese 不支持的功能 \~english Not supported function
MV_E_BUFOVER = 0x80000002 # < \~chinese 缓存已满 \~english Buffer overflow
MV_E_CALLORDER = 0x80000003 # < \~chinese 函数调用顺序错误 \~english Function calling order error
MV_E_PARAMETER = 0x80000004 # < \~chinese 错误的参数 \~english Incorrect parameter
MV_E_RESOURCE = 0x80000006 # < \~chinese 资源申请失败 \~english Applying resource failed
MV_E_NODATA = 0x80000007 # < \~chinese 无数据 \~english No data
MV_E_PRECONDITION = 0x80000008 # < \~chinese 前置条件有误,或运行环境已发生变化 \~english Precondition error, or running environment changed
MV_E_VERSION = 0x80000009 # < \~chinese 版本不匹配 \~english Version mismatches
MV_E_NOENOUGH_BUF = 0x8000000A # < \~chinese 传入的内存空间不足 \~english Insufficient memory
MV_E_ABNORMAL_IMAGE = 0x8000000B # < \~chinese 异常图像,可能是丢包导致图像不完整 \~english Abnormal image, maybe incomplete image because of lost packet
MV_E_LOAD_LIBRARY = 0x8000000C # < \~chinese 动态导入DLL失败 \~english Load library failed
MV_E_NOOUTBUF = 0x8000000D # < \~chinese 没有可输出的缓存 \~english No Avaliable Buffer
MV_E_UNKNOW = 0x800000FF # < \~chinese 未知的错误 \~english Unknown error
# GenICam系列错误:范围0x80000100-0x800001FF
MV_E_GC_GENERIC = 0x80000100 # < \~chinese 通用错误 \~english General error
MV_E_GC_ARGUMENT = 0x80000101 # < \~chinese 参数非法 \~english Illegal parameters
MV_E_GC_RANGE = 0x80000102 # < \~chinese 值超出范围 \~english The value is out of range
MV_E_GC_PROPERTY = 0x80000103 # < \~chinese 属性 \~english Property
MV_E_GC_RUNTIME = 0x80000104 # < \~chinese 运行环境有问题 \~english Running environment error
MV_E_GC_LOGICAL = 0x80000105 # < \~chinese 逻辑错误 \~english Logical error
MV_E_GC_ACCESS = 0x80000106 # < \~chinese 节点访问条件有误 \~english Node accessing condition error
MV_E_GC_TIMEOUT = 0x80000107 # < \~chinese 超时 \~english Timeout
MV_E_GC_DYNAMICCAST = 0x80000108 # < \~chinese 转换异常 \~english Transformation exception
MV_E_GC_UNKNOW = 0x800001FF # < \~chinese GenICam未知错误 \~english GenICam unknown error
# GigE_STATUS对应的错误码:范围0x80000200-0x800002FF
MV_E_NOT_IMPLEMENTED = 0x80000200 # < \~chinese 命令不被设备支持 \~english The command is not supported by device
MV_E_INVALID_ADDRESS = 0x80000201 # < \~chinese 访问的目标地址不存在 \~english The target address being accessed does not exist
MV_E_WRITE_PROTECT = 0x80000202 # < \~chinese 目标地址不可写 \~english The target address is not writable
MV_E_ACCESS_DENIED = 0x80000203 # < \~chinese 设备无访问权限 \~english No permission
MV_E_BUSY = 0x80000204 # < \~chinese 设备忙,或网络断开 \~english Device is busy, or network disconnected
MV_E_PACKET = 0x80000205 # < \~chinese 网络包数据错误 \~english Network data packet error
MV_E_NETER = 0x80000206 # < \~chinese 网络相关错误 \~english Network error
MV_E_IP_CONFLICT = 0x80000221 # < \~chinese 设备IP冲突 \~english Device IP conflict
# USB_STATUS对应的错误码:范围0x80000300-0x800003FF
MV_E_USB_READ = 0x80000300 # < \~chinese 读usb出错 \~english Reading USB error
MV_E_USB_WRITE = 0x80000301 # < \~chinese 写usb出错 \~english Writing USB error
MV_E_USB_DEVICE = 0x80000302 # < \~chinese 设备异常 \~english Device exception
MV_E_USB_GENICAM = 0x80000303 # < \~chinese GenICam相关错误 \~english GenICam error
MV_E_USB_BANDWIDTH = 0x80000304 # < \~chinese 带宽不足 该错误码新增 \~english Insufficient bandwidth, this error code is newly added
MV_E_USB_DRIVER = 0x80000305 # < \~chinese 驱动不匹配或者未装驱动 \~english Driver mismatch or unmounted drive
MV_E_USB_UNKNOW = 0x800003FF # < \~chinese USB未知的错误 \~english USB unknown error
# 升级时对应的错误码:范围0x80000400-0x800004FF
MV_E_UPG_FILE_MISMATCH = 0x80000400 # < \~chinese 升级固件不匹配 \~english Firmware mismatches
MV_E_UPG_LANGUSGE_MISMATCH = 0x80000401 # < \~chinese 升级固件语言不匹配 \~english Firmware language mismatches
MV_E_UPG_CONFLICT = 0x80000402 # < \~chinese 升级冲突(设备已经在升级了再次请求升级即返回此错误) \~english Upgrading conflicted (repeated upgrading requests during device upgrade)
MV_E_UPG_INNER_ERR = 0x80000403 # < \~chinese 升级时设备内部出现错误 \~english Camera internal error during upgrade
MV_E_UPG_UNKNOW = 0x800004FF # < \~chinese 升级时未知错误 \~english Unknown error during upgrade
from ctypes import *
PixelType_Gvsp_BGR12_Packed = 36700187
PixelType_Gvsp_COORD3D_DEPTH_PLUS_MASK = -2112094207
PixelType_Gvsp_RGB10V1_Packed = 35651612
PixelType_Gvsp_BayerRG12_Packed = 17563691
PixelType_Gvsp_RGB12_Planar = 36700195
PixelType_Gvsp_YUV411_Packed = 34340894
PixelType_Gvsp_YUV444_Packed = 35127328
PixelType_Gvsp_BGR10_Packed = 36700185
PixelType_Gvsp_YCBCR422_8 = 34603067
PixelType_Gvsp_YCBCR709_422_8 = 34603073
PixelType_Gvsp_RGB12_Packed = 36700186
PixelType_Gvsp_Coord3D_ABC32f_Planar = 39846081
PixelType_Gvsp_Mono8_Signed = 17301506
PixelType_Gvsp_YUV422_YUYV_Packed = 34603058
PixelType_Gvsp_Mono4p = 17039417
PixelType_Gvsp_BayerGR12_Packed = 17563690
PixelType_Gvsp_Coord3D_ABC32 = -2107625471
PixelType_Gvsp_Coord3D_AB32f = -2109722622
PixelType_Gvsp_YCBCR709_411_8_CBYYCRYY = 34340930
PixelType_Gvsp_YCBCR709_422_8_CBYCRY = 34603077
PixelType_Gvsp_Coord3D_AB32 = -2109722621
PixelType_Gvsp_YCBCR601_422_8_CBYCRY = 34603076
PixelType_Gvsp_YCBCR709_8_CBYCR = 35127360
PixelType_Gvsp_Coord3D_AC32f = 36176066
PixelType_Gvsp_YCBCR8_CBYCR = 35127354
PixelType_Gvsp_YCBCR411_8_CBYYCRYY = 34340924
PixelType_Gvsp_Coord3D_ABC32f = 39846080
PixelType_Gvsp_YUV422_Packed = 34603039
PixelType_Gvsp_Coord3D_ABC16 = 36700345
PixelType_Gvsp_RGB10_Planar = 36700194
PixelType_Gvsp_RGB8_Planar = 35127329
PixelType_Gvsp_RGB10_Packed = 36700184
PixelType_Gvsp_Coord3D_C32 = -2128596986
PixelType_Gvsp_RGB16_Packed = 36700211
PixelType_Gvsp_YCBCR422_8_CBYCRY = 34603075
PixelType_Gvsp_YCBCR601_411_8_CBYYCRYY = 34340927
PixelType_Gvsp_BGRA8_Packed = 35651607
PixelType_Gvsp_Jpeg = -2145910783
PixelType_Gvsp_YCBCR601_422_8 = 34603070
PixelType_Gvsp_Coord3D_C32f = 18874559
PixelType_Gvsp_BayerGB12_Packed = 17563692
PixelType_Gvsp_BayerRG16 = 17825839
PixelType_Gvsp_BayerGB10_Packed = 17563688
PixelType_Gvsp_RGB12V1_Packed = 35913780
PixelType_Gvsp_RGB16_Planar = 36700196
PixelType_Gvsp_BGR565_Packed = 34603062
PixelType_Gvsp_Mono16 = 17825799
PixelType_Gvsp_BayerBG10 = 17825807
PixelType_Gvsp_Coord3D_AC32f_64 = 37748930
PixelType_Gvsp_RGBA8_Packed = 35651606
PixelType_Gvsp_Mono12 = 17825797
PixelType_Gvsp_Coord3D_A32f = 18874557
PixelType_Gvsp_YCBCR601_8_CBYCR = 35127357
PixelType_Gvsp_BayerGB16 = 17825840
PixelType_Gvsp_Coord3D_AC32 = -2109722620
PixelType_Gvsp_BayerBG16 = 17825841
PixelType_Gvsp_Coord3D_AC32f_Planar = 37748931
PixelType_Gvsp_BayerBG10_Packed = 17563689
PixelType_Gvsp_RGB8_Packed = 35127316
PixelType_Gvsp_BGR8_Packed = 35127317
PixelType_Gvsp_BayerGR16 = 17825838
PixelType_Gvsp_BayerGR10_Packed = 17563686
PixelType_Gvsp_Mono8 = 17301505
PixelType_Gvsp_Mono14 = 17825829
PixelType_Gvsp_BayerGB10 = 17825806
PixelType_Gvsp_Undefined = -1
PixelType_Gvsp_BayerRG8 = 17301513
PixelType_Gvsp_BayerGB12 = 17825810
PixelType_Gvsp_Mono12_Packed = 17563654
PixelType_Gvsp_BayerBG8 = 17301515
PixelType_Gvsp_BayerBG12_Packed = 17563693
PixelType_Gvsp_Mono1p = 16842807
PixelType_Gvsp_Mono2p = 16908344
PixelType_Gvsp_RGB565_Packed = 34603061
PixelType_Gvsp_RGB10V2_Packed = 35651613
PixelType_Gvsp_BayerRG12 = 17825809
PixelType_Gvsp_Mono10_Packed = 17563652
PixelType_Gvsp_BayerGR8 = 17301512
PixelType_Gvsp_BayerGB8 = 17301514
PixelType_Gvsp_BayerGR12 = 17825808
PixelType_Gvsp_BayerGR10 = 17825804
PixelType_Gvsp_BayerRG10 = 17825805
PixelType_Gvsp_BayerBG12 = 17825811
PixelType_Gvsp_Coord3D_A32 = -2128596987
PixelType_Gvsp_Mono10 = 17825795
PixelType_Gvsp_BayerRG10_Packed = 17563687
__all__ = ['PixelType_Gvsp_BayerRG8',
'PixelType_Gvsp_YCBCR422_8',
'PixelType_Gvsp_Coord3D_ABC32',
'PixelType_Gvsp_Coord3D_AB32f',
'PixelType_Gvsp_COORD3D_DEPTH_PLUS_MASK',
'PixelType_Gvsp_RGB10_Packed',
'PixelType_Gvsp_RGB10V1_Packed',
'PixelType_Gvsp_RGB8_Planar',
'PixelType_Gvsp_RGBA8_Packed',
'PixelType_Gvsp_RGB8_Packed',
'PixelType_Gvsp_BayerBG12',
'PixelType_Gvsp_Coord3D_AC32f_Planar',
'PixelType_Gvsp_BayerBG10_Packed',
'PixelType_Gvsp_YCBCR709_422_8_CBYCRY',
'PixelType_Gvsp_Coord3D_A32f',
'PixelType_Gvsp_YUV411_Packed',
'PixelType_Gvsp_BayerBG12_Packed',
'PixelType_Gvsp_RGB16_Packed',
'PixelType_Gvsp_BayerRG12',
'PixelType_Gvsp_BayerRG10',
'PixelType_Gvsp_BayerRG16',
'PixelType_Gvsp_YCBCR709_411_8_CBYYCRYY',
'PixelType_Gvsp_BayerGB12_Packed',
'PixelType_Gvsp_Coord3D_AC32f',
'PixelType_Gvsp_BayerRG12_Packed',
'PixelType_Gvsp_Coord3D_AB32',
'PixelType_Gvsp_BGR12_Packed',
'PixelType_Gvsp_BayerGR10_Packed',
'PixelType_Gvsp_Coord3D_AC32',
'PixelType_Gvsp_RGB12_Planar',
'PixelType_Gvsp_YCBCR709_422_8',
'PixelType_Gvsp_BGR8_Packed',
'PixelType_Gvsp_Jpeg',
'PixelType_Gvsp_Coord3D_AC32f_64',
'PixelType_Gvsp_YUV422_Packed',
'PixelType_Gvsp_Mono8_Signed',
'PixelType_Gvsp_BayerBG10',
'PixelType_Gvsp_BayerBG16',
'PixelType_Gvsp_BayerGR8',
'PixelType_Gvsp_RGB16_Planar',
'PixelType_Gvsp_Mono4p',
'PixelType_Gvsp_BayerRG10_Packed',
'PixelType_Gvsp_Mono8',
'PixelType_Gvsp_BayerGR16',
'PixelType_Gvsp_BayerGR10',
'PixelType_Gvsp_BGRA8_Packed',
'PixelType_Gvsp_BayerGR12',
'PixelType_Gvsp_Mono12_Packed',
'PixelType_Gvsp_YCBCR709_8_CBYCR',
'PixelType_Gvsp_Coord3D_A32',
'PixelType_Gvsp_YCBCR601_422_8',
'PixelType_Gvsp_Coord3D_C32',
'PixelType_Gvsp_YCBCR411_8_CBYYCRYY',
'PixelType_Gvsp_Undefined',
'PixelType_Gvsp_BayerGR12_Packed',
'PixelType_Gvsp_YCBCR601_411_8_CBYYCRYY',
'PixelType_Gvsp_RGB10_Planar',
'PixelType_Gvsp_BayerGB16',
'PixelType_Gvsp_BayerGB10',
'PixelType_Gvsp_BayerGB12',
'PixelType_Gvsp_BGR565_Packed',
'PixelType_Gvsp_Mono1p',
'PixelType_Gvsp_Coord3D_ABC16',
'PixelType_Gvsp_YUV444_Packed',
'PixelType_Gvsp_YUV422_YUYV_Packed',
'PixelType_Gvsp_BayerBG8',
'PixelType_Gvsp_Coord3D_C32f',
'PixelType_Gvsp_BGR10_Packed',
'PixelType_Gvsp_BayerGB10_Packed',
'PixelType_Gvsp_Coord3D_ABC32f_Planar',
'PixelType_Gvsp_Coord3D_ABC32f',
'PixelType_Gvsp_YCBCR422_8_CBYCRY',
'PixelType_Gvsp_RGB12_Packed',
'PixelType_Gvsp_Mono12',
'PixelType_Gvsp_Mono10',
'PixelType_Gvsp_Mono16',
'PixelType_Gvsp_Mono2p',
'PixelType_Gvsp_Mono14',
'PixelType_Gvsp_RGB10V2_Packed',
'PixelType_Gvsp_RGB12V1_Packed',
'PixelType_Gvsp_Mono10_Packed',
'PixelType_Gvsp_YCBCR601_8_CBYCR',
'PixelType_Gvsp_BayerGB8',
'PixelType_Gvsp_YCBCR8_CBYCR',
'PixelType_Gvsp_RGB565_Packed',
'PixelType_Gvsp_YCBCR601_422_8_CBYCRY']
File added
[video]
# 配置是否播放视频,1:播放,0:不播放
is_show=0
# 配置摄像头宽高,用,间隔
size=[1440,1080]
[point]
# 配置激光点的面积范围,用,间隔,用于过滤干扰点
area=[0,100]
# 配置激光点亮度下限,软件只捕获RGB平均值>该设定值的激光点
# 调整该值,满足以下要求:除激光外,其他内容的亮度均小于该值
light=20
# 配置鼠标是否跟随,1:跟随,0:不跟随
is_mouse_follow=1
# 配置鼠标跟随的帧系数,浮点数,0~1,表示每秒鼠标跟随(视频帧速率 x 系数)次
# 主要用于在低性能机器上解析高帧速率视频,实现降采样,普通机器默认配置1(即正常采样)
fps_ratio=1
# 配置激光的监视系数,浮点数,表示激光可超出屏幕的百分比
# 默认配置0,如果激光直径比较大,可以配置该系数,如0.005
monitor_ratio=0
[correct]
# position1和position2用于给摄像头拍到的屏幕4个角进行定位,坐标为屏幕xy坐标
# 配置项为二维数组,分别表示左上、左下、右下、右上4个坐标点
position1=[[72,147],[119,890],[1326,905],[1392,161]]
position2=[[51,121],[110,867],[1312,874],[1380,127]]
[screen]
# 配置显示器是分屏还是合屏,1:合屏,0:分屏
is_merge=0
screen_width = 3840
screen_height = 1080
#layout = [{"id": "screen1", "ip": "192.168.31.150", "anchor": [0, 0], "width": 1920, "height": 1080}, {"id": "screen2", "ip": "192.168.31.151", "anchor": [1920, 0], "width": 1920, "height": 1080}]
layout = [{"id": "screen1", "ip": "192.168.31.150", "anchor": [0, 0], "width": 3840, "height": 1080}]
# 指令字符串配置
[udp_service]
port=18300
# 指令字符串配置
[order]
left_clicked=btn:left_clicked\r\n
left_long_clicked=btn:left_long_clicked\r\n
left_long_clicked_release=btn:left_long_clicked_release\r\n
left_double_clicked=btn:left_double_clicked\r\n
right_clicked=btn:right_clicked\r\n
right_long_clicked=btn:right_long_clicked\r\n
right_long_clicked_release=btn:right_long_clicked_release\r\n
right_double_clicked=btn:right_double_clicked\r\n
page_up_clicked=btn:page_up_clicked\r\n
page_down_clicked=btn:page_down_clicked\r\n
switch_clicked=btn:switch_clicked\r\n
audio_clicked=btn:audio_clicked\r\n
\ No newline at end of file
import socket
import time,random
class KM:
def __init__(self,ip):
self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
self.sock.settimeout(1)
self.ip=ip
self.sync_mode=True
def __del__(self):
self.Close()
def Close(self):
if self.sock!=None:
self.sock.close()
self.sock=None
def Send(self,msg):
self.sock.sendto(msg.encode('ascii'),(self.ip,2333))
def Recv(self):
try:
data,_ = self.sock.recvfrom(128)
return data
except socket.timeout:
self.Close()
self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
self.sock.settimeout(1)
return [0xff];
def SendCmd(self,type,params):
cmd=type+"="+",".join([str(s) for s in params])+"\r\n"
self.Send(cmd)
if self.sync_mode:
return self.Recv()
return None
@staticmethod
def Delay(millisecond):
time.sleep(millisecond/1000)
@staticmethod
def DelayRandom(min,max):
time.sleep(random.randint(min,max)/1000)
def GetName(self):
data=self.SendCmd("P",[0])
if data[0]==0xff:
return ""
else:
data=data[:data.index(0)]
return data.decode("gbk")
def GetID(self):
data=self.SendCmd("P",[1])
if len(data)!=4:
return 0
return data[0]<<24|data[1]<<16|data[2]<<8|data[3]
#Setting
def SetScreenRes(self,width,height):
self.SendCmd("S",[0,width,height])
def SetSpeedMode(self,on):
self.sync_mode=not on
self.SendCmd("S",[1,1 if on else 0])
def Reboot(self):
self.SendCmd("S",[2])
#Mouse
def MoveTo(self,x,y):
self.SendCmd("M",[0,x,y])
def MoveD(self,x,y,shift=0,time=0):
self.SendCmd("M",[1,x,y,shift,time])
def MoveR(self,dx,dy):
self.SendCmd("M",[2,dx,dy])
def LeftDown(self):
self.SendCmd("M",[3])
def LeftUp(self):
self.SendCmd("M",[4])
def LeftClick(self,min=0,max=0):
self.SendCmd("M",[5,min,max])
def LeftDoubleClick(self,min=0,max=0):
self.SendCmd("M",[6,min,max])
def RightDown(self):
self.SendCmd("M",[7])
def RightUp(self):
self.SendCmd("M",[8])
def RightClick(self,min=0,max=0):
self.SendCmd("M",[9,min,max])
def MouseWheel(self,delta):
self.SendCmd("M",[10,delta])
def MiddleDown(self):
self.SendCmd("M",[11])
def MiddleUp(self):
self.SendCmd("M",[12])
def MiddleClick(self,min=0,max=0):
self.SendCmd("M",[13,min,max])
def MouseAllUp(self):
self.SendCmd("M",[14])
#Keyboard
def KeyDown(self,scancode):
self.SendCmd("K",[0,scancode])
def KeyUp(self,scancode):
self.SendCmd("K",[1,scancode])
def KeyPress(self,scancode,min=0,max=0):
self.SendCmd("K",[2,scancode,min,max])
def KeyDownVirtual(self,virtualcode):
scancode=self.GetScanCodeFromVirtualCode(virtualcode)
self.SendCmd("K",[0,scancode])
def KeyUpVirtual(self,virtualcode):
scancode=self.GetScanCodeFromVirtualCode(virtualcode)
self.SendCmd("K",[1,scancode])
def KeyPressVirtual(self,virtualcode,min=0,max=0):
scancode=self.GetScanCodeFromVirtualCode(virtualcode)
self.SendCmd("K",[2,scancode,min,max])
def KeyDownName(self,keyname):
scancode=self.GetScanCodeFromKeyName(keyname)
self.SendCmd("K",[0,scancode])
def KeyUpName(self,keyname):
scancode=self.GetScanCodeFromKeyName(keyname)
self.SendCmd("K",[1,scancode])
def KeyPressName(self,keyname,min=0,max=0):
scancode=self.GetScanCodeFromKeyName(keyname)
self.SendCmd("K",[2,scancode,min,max])
def KeyAllUp(self):
self.SendCmd("K",[3])
@staticmethod
def GetScanCodeFromVirtualCode(vcode):
keymap={
"65":4,"66":5,"67":6,"68":7,"69":8,"70":9,"71":10,"72":11,"73":12,"74":13,"75":14,"76":15,"77":16,"78":17,"79":18,
"80":19,"81":20,"82":21,"83":22,"84":23,"85":24,"86":25,"87":26,"88":27,"89":28,"90":29,"49":30,"50":31,"51":32,"52":33,
"53":34,"54":35,"55":36,"56":37,"57":38,"48":39,"13":40,"27":41,"8":42,"9":43,"32":44,"189":45,"187":46,"219":47,"221":48,
"220":49,"186":51,"222":52,"192":53,"188":54,"190":55,"191":56,"20":57,"112":58,"113":59,"114":60,"115":61,"116":62,"117":63,
"118":64,"119":65,"120":66,"121":67,"122":68,"123":69,"44":70,"145":71,"19":72,"19":72,"45":73,"36":74,"33":75,"46":76,"35":77,
"34":78,"39":79,"37":80,"40":81,"38":82,"144":83,"111":84,"96":85,"109":86,"107":87,"108":88,"97":89,"98":90,"99":91,"100":92,
"101":93,"102":94,"103":95,"104":96,"105":97,"96":98,"110":99,"93":101,"146":103,"173":127,"175":128,"174":129,"162":224,"160":225,
"164":226,"91":227,"163":228,"161":229,"165":230,"92":231,"17":224,"16":225,"18":226
}
vcode=str(vcode)
if vcode in keymap:
return keymap[vcode]
else:
return 0
@staticmethod
def GetScanCodeFromKeyName(keyname):
keymap={
"a":4,"b":5,"c":6,"d":7,"e":8,"f":9,"g":10,"h":11,"i":12,"j":13,"k":14,"l":15,"m":16,"n":17,"o":18,"p":19,"q":20,
"r":21,"s":22,"t":23,"u":24,"v":25,"w":26,"x":27,"y":28,"z":29,"1":30,"2":31,"3":32,"4":33,"5":34,"6":35,"7":36,
"8":37,"9":38,"0":39,"enter":40,"esc":41,"backspace":42,"tab":43,"space":44,"空格键":44,"-":45,"=":46,"[":47,"]":48,
"\\":49,";":51,"'":52,"`":53,",":54,".":55,"/":56,"capslock":57,"f1":58,"f2":59,"f3":60,"f4":61,"f5":62,"f6":63,"f7":64,
"f8":65,"f9":66,"f10":67,"f11":68,"f12":69,"printscreen":70,"scrolllock":71,"pause":72,"break":72,"insert":73,"home":74,
"pageup":75,"delete":76,"end":77,"pagedown":78,"right":79,"left":80,"down":81,"up":82,"numlock":83,"小键盘/":84,"小键盘*":85,
"小键盘-":86,"小键盘+":87,"小键盘enter":88,"小键盘1":89,"小键盘2":90,"小键盘3":91,"小键盘4":92,"小键盘5":93,"小键盘6":94,
"小键盘7":95,"小键盘8":96,"小键盘9":97,"小键盘0":98,"小键盘.":99,"menu":101,"小键盘=":103,"静音":127,"音量加":128,"音量减":129,
"lctrl":224,"lshift":225,"lalt":226,"lwin":227,"rctrl":228,"rshift":229,"ralt":230,"rwin":231,
"ctrl":224,"shift":225,"alt":226,"win":227
}
keyname=keyname.lower()
if keyname in keymap:
return keymap[keyname]
else:
return 0
# -*- coding: utf-8 -*-
import win32con
import ctypes
import os
class CursorHider():
# 开始隐藏鼠标
def cursor_hider_open():
# 通过注册表生成透明的鼠标方案
cwd = os.getcwd()
command = 'reg add "HKCU\Control Panel\Cursors" /f /ve /t REG_SZ /d "videomouse"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Scheme Source" /t REG_DWORD /d 1\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Arrow" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Help" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "AppStarting" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Wait" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Crosshair" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "IBeam" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "NWPen" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "No" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNS" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeWE" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNWSE" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNESW" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeAll" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "UpArrow" /t REG_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Person" /t REG_EXPAND_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Hand" /t REG_EXPAND_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Pin" /t REG_EXPAND_SZ /d "' + cwd + '/blank.cur"\
&& reg add "HKCU\Control Panel\Cursors\Schemes" /f /v "videomouse" /t REG_EXPAND_SZ /d "' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur,' + cwd + '/blank.cur"'
os.system(command)
# 应用鼠标方案
dll = ctypes.windll.LoadLibrary('user32')
dll.SystemParametersInfoW(win32con.SPI_SETCURSORS,0,0,2)
# 取消鼠标隐藏
def cursor_hider_close():
# 删除注册表中透明的鼠标方案
command = 'reg add "HKCU\Control Panel\Cursors" /f /ve /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Scheme Source" /t REG_DWORD /d 0\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Arrow" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Help" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "AppStarting" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Wait" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Crosshair" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "IBeam" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "NWPen" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "No" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNS" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeWE" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNWSE" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNESW" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeAll" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "UpArrow" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Person" /t REG_EXPAND_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Hand" /t REG_EXPAND_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Pin" /t REG_EXPAND_SZ /d ""\
&& reg delete "HKCU\Control Panel\Cursors\Schemes" /f /v "videomouse"'
os.system(command)
# 应用鼠标方案
dll = ctypes.windll.LoadLibrary('user32')
dll.SystemParametersInfoW(win32con.SPI_SETCURSORS,0,0,2)
import win32api,win32con
class MouseEvent():
def mouse_move(x, y, main_screen_width, main_screen_height):
dx = round(x*65536/main_screen_width)
dy = round(y*65536/main_screen_height)
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE | win32con.MOUSEEVENTF_MOVE, dx, dy, 0, 0)
def mouse_left_click():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def mouse_left_dbclick():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def mouse_right_click():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN | win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
def mouse_right_dbclick():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN | win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN | win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
def mouse_middle_up():
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, 100, 0)
def mouse_middle_down():
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, -100, 0)
def mouse_left_down():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
def mouse_left_up():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def mouse_right_down():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
def mouse_right_up():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
\ No newline at end of file
import win32api,win32con
from km import KM
class MouseEvent():
def mouse_move(x, y, main_screen_width, main_screen_height):
dx = round(x*65536/main_screen_width)
dy = round(y*65536/main_screen_height)
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE | win32con.MOUSEEVENTF_MOVE, dx, dy, 0, 0)
def mouse_left_click():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def mouse_left_dbclick():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN | win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def mouse_right_click():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN | win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
def mouse_right_dbclick():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN | win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN | win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
def mouse_middle_up():
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, 100, 0)
def mouse_middle_down():
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, -100, 0)
def mouse_left_down():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
def mouse_left_up():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def mouse_right_down():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
def mouse_right_up():
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
class RemoteMouseEvent():
#def __init__(self, sip1, sip2, main_screen_width, main_screen_height):
def __init__(self, sip1):
self.cx = None
self.cy = None
self.km1 = KM(sip1)
def setScreenRes(self, width, height):
self.km1.SetScreenRes(width, height)
def setSpeedMode(self, on):
self.km1.SetSpeedMode(on)
def _update(self, x, y):
self.x = int(x)
self.y = int(y)
def get_km(self):
return self.km1
#print(self.x, self.y, self.main_screen_width, self.main_screen_height)
#if self.x is None or self.main_screen_width is None:
#return None
#return self.km1 if self.x < self.main_screen_width else self.km2
def mouse_move(self, x, y, main_screen_width, main_screen_height):
self._update(x, y)
km = self.get_km()
km.MoveTo(int(x), int(y))
def mouse_left_click(self):
km = self.get_km()
km.LeftClick()
def mouse_left_dbclick(self):
km = self.get_km()
km.LeftDoubleClick()
def mouse_right_click(self):
km = self.get_km()
km.RightClick()
def mouse_right_dbclick(self):
km = self.get_km()
km.RightClick()
km.RightClick()
def mouse_wheel_up(self):
km = self.get_km()
km.MouseWheel(2)
def mouse_wheel_down(self):
km=self.get_km()
km.MouseWheel(-2)
def mouse_middle_up(self):
km = self.get_km()
km.MiddleUp()
def mouse_middle_down(self):
km = self.get_km()
km.MiddleDown()
def mouse_left_down(self):
km = self.get_km()
km.LeftDown()
def mouse_left_up(self):
km = self.get_km()
km.LeftUp()
def mouse_right_down(self):
km = self.get_km()
km.RightDown()
def mouse_right_up(self):
km = self.get_km()
km.RightUp()
class MultiScreenMouseEvent():
def __init__(self, screen_width, screen_height, layout, speed_mode = True) -> None:
self.total_screen_width = screen_width
self.total_screen_height = screen_height
self.layout = layout
self.speed_mode = speed_mode
self.kms = {}
for s in self.layout:
km = KM(s["ip"])
km.SetScreenRes(s["width"], s["height"])
km.SetSpeedMode(speed_mode)
self.kms[s["id"]] = km
self.current_screen = None
def find_screen_and_relative_coords(self, point):
for screen in self.layout:
x, y = point
anchor_x, anchor_y = screen['anchor']
width, height = screen['width'], screen['height']
if anchor_x <= x < anchor_x + width and anchor_y <= y < anchor_y + height:
#relative_coords = [x, y - anchor_y]
relative_coords = [x - anchor_x, y - anchor_y]
return screen, relative_coords
return None, None
def __getattr__(self, name):
if name == "mouse_move":
def method(ax, ay):
s, coords = self.find_screen_and_relative_coords((ax, ay))
km = self.kms[s["id"]]
self.current_screen = s["id"]
#self.current_screen = "screen1"
rx, ry = coords[0], coords[1]
print(self.current_screen, int(rx), int(ry))
km.MoveTo(int(rx), int(ry))
return method
else:
def method(*args, **kwargs):
km = self.kms[self.current_screen]
getattr(km, name)(*args, **kwargs)
return method
\ No newline at end of file
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
import pythoncom
class VolumeEvent():
def volume_change():
pythoncom.CoInitialize()
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
# 判断是否静音,mute为1代表是静音,为0代表不是静音
mute = volume.GetMute()
if mute == 0:
volume.SetMute(1, None)
else:
volume.SetMute(0, None)
\ No newline at end of file
import sys
import threading
import msvcrt
import numpy as np
import time
from ctypes import *
sys.path.append("./MvImport")
from MvCameraControl_class import *
g_bExit = False
class GigeE():
def startCamera(nConnectionNum):
deviceList = MV_CC_DEVICE_INFO_LIST()
#tlayerType = MV_GIGE_DEVICE | MV_USB_DEVICE | MV_UNKNOW_DEVICE | MV_1394_DEVICE | MV_CAMERALINK_DEVICE
tlayerType = MV_GIGE_DEVICE
# ch:枚举设备 | en:Enum device
ret = MvCamera.MV_CC_EnumDevices(tlayerType, deviceList)
if ret != 0:
print("enum devices fail! ret[0x%x]" % ret)
#sys.exit()
return None
if deviceList.nDeviceNum == 0:
print("find no device!")
#sys.exit()
return None
print("Find %d devices!" % deviceList.nDeviceNum)
for i in range(0, deviceList.nDeviceNum):
mvcc_dev_info = cast(deviceList.pDeviceInfo[i], POINTER(MV_CC_DEVICE_INFO)).contents
if mvcc_dev_info.nTLayerType == MV_GIGE_DEVICE:
print("\ngige device: [%d]" % i)
strModeName = ""
for per in mvcc_dev_info.SpecialInfo.stGigEInfo.chModelName:
strModeName = strModeName + chr(per)
print("device model name: %s" % strModeName)
nip1 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24)
nip2 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16)
nip3 = ((mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8)
nip4 = (mvcc_dev_info.SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff)
print("current ip: %d.%d.%d.%d\n" % (nip1, nip2, nip3, nip4))
elif mvcc_dev_info.nTLayerType == MV_USB_DEVICE:
print("\nu3v device: [%d]" % i)
strModeName = ""
for per in mvcc_dev_info.SpecialInfo.stUsb3VInfo.chModelName:
if per == 0:
break
strModeName = strModeName + chr(per)
print("device model name: %s" % strModeName)
strSerialNumber = ""
for per in mvcc_dev_info.SpecialInfo.stUsb3VInfo.chSerialNumber:
if per == 0:
break
strSerialNumber = strSerialNumber + chr(per)
print("user serial number: %s" % strSerialNumber)
# nConnectionNum = input("please input the number of the device to connect:")
if int(nConnectionNum) >= deviceList.nDeviceNum:
print("intput error!")
#sys.exit()
return None
# ch:创建相机实例 | en:Creat Camera Object
cam = MvCamera()
# ch:选择设备并创建句柄 | en:Select device and create handle
stDeviceList = cast(deviceList.pDeviceInfo[int(nConnectionNum)], POINTER(MV_CC_DEVICE_INFO)).contents
ret = cam.MV_CC_CreateHandle(stDeviceList)
if ret != 0:
print("create handle fail! ret[0x%x]" % ret)
#sys.exit()
return None
# ch:打开设备 | en:Open device
ret = cam.MV_CC_OpenDevice(MV_ACCESS_Exclusive, 0)
if ret != 0:
print("open device fail! ret[0x%x]" % ret)
#sys.exit()
return None
# ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
if stDeviceList.nTLayerType == MV_GIGE_DEVICE:
nPacketSize = cam.MV_CC_GetOptimalPacketSize()
if int(nPacketSize) > 0:
ret = cam.MV_CC_SetIntValue("GevSCPSPacketSize", nPacketSize)
if ret != 0:
print("Warning: Set Packet Size fail! ret[0x%x]" % ret)
else:
print("Warning: Get Packet Size fail! ret[0x%x]" % nPacketSize)
stBool = c_bool(False)
ret = cam.MV_CC_GetBoolValue("AcquisitionFrameRateEnable", stBool)
if ret != 0:
print("get AcquisitionFrameRateEnable fail! ret[0x%x]" % ret)
#sys.exit()
return None
# ch:设置触发模式为off | en:Set trigger mode as off
ret = cam.MV_CC_SetEnumValue("TriggerMode", MV_TRIGGER_MODE_OFF)
if ret != 0:
print("set trigger mode fail! ret[0x%x]" % ret)
#sys.exit()
return None
# ch:开始取流 | en:Start grab image
ret = cam.MV_CC_StartGrabbing()
if ret != 0:
print("start grabbing fail! ret[0x%x]" % ret)
#sys.exit()
return None
return cam
##############################
# try:
# hThreadHandle = threading.Thread(target=work_thread, args=(cam, None, None))
# hThreadHandle.start()
# except:
# print ("error: unable to start thread")
# g_bExit = True
# hThreadHandle.join()
def closeCamera(cam):
# ch:停止取流 | en:Stop grab image
ret = cam.MV_CC_StopGrabbing()
if ret != 0:
print("stop grabbing fail! ret[0x%x]" % ret)
#sys.exit()
return None
# ch:关闭设备 | Close device
ret = cam.MV_CC_CloseDevice()
if ret != 0:
print("close deivce fail! ret[0x%x]" % ret)
#sys.exit()
return None
# ch:销毁句柄 | Destroy handle
ret = cam.MV_CC_DestroyHandle()
if ret != 0:
print("destroy handle fail! ret[0x%x]" % ret)
#sys.exit()
return None
def GetImage(cam, height, width):
sec = 0
data_buf = None
stOutFrame = MV_FRAME_OUT()
memset(byref(stOutFrame), 0, sizeof(stOutFrame))
ret = cam.MV_CC_GetImageBuffer(stOutFrame, 1000)
if None != stOutFrame.pBufAddr and 0 == ret:
if data_buf == None:
data_buf = (c_ubyte * stOutFrame.stFrameInfo.nFrameLen)()
# print("get one frame: Width[%d], Height[%d], nFrameNum[%d]" % (
# stOutFrame.stFrameInfo.nWidth, stOutFrame.stFrameInfo.nHeight, stOutFrame.stFrameInfo.nFrameNum))
cdll.msvcrt.memcpy(byref(data_buf), stOutFrame.pBufAddr, stOutFrame.stFrameInfo.nFrameLen)
temp = np.asarray(data_buf)
temp = temp.reshape((height, width)) #注意 这里要改成使用相机的宽和高
nRet = cam.MV_CC_FreeImageBuffer(stOutFrame)
return temp
else:
print("no data[0x%x]" % ret)
def GetFps(cam):
return cam.MV_CC_GetFrameRate()
from collections import deque
import itertools
import numpy as np
class WeightedMovingAverageFilter:
def __init__(self, weights, disabled=False, threshold=0.95):
self.weights = weights
self.values = deque(maxlen=len(weights))
self.disabled = disabled
self.threshold = threshold
def stable(self):
cv = np.std(self.values) / np.mean(self.values)
return cv >= self.threshold
def update(self, new_value):
if self.disabled:
return new_value
self.values.append(new_value)
if len(self.values) < len(self.weights):
return new_value
else:
if self.stable():
avg_x = sum(x for x, y in self.values) / len(self.values)
avg_y = sum(y for x, y in self.values) / len(self.values)
return (avg_x, avg_y)
return [sum(w * v[i] for w, v in zip(self.weights, reversed(self.values))) for i in range(2)]
class ExponentialMovingAverageFilter:
def __init__(self, alpha):
self.alpha = alpha
self.value = None
def update(self, new_value):
if self.value is None:
self.value = new_value
else:
self.value = [(1 - self.alpha) * old + self.alpha * new for old, new in zip(self.value, new_value)]
return self.value
if __name__ == "__main__":
filter = WeightedMovingAverageFilter(weights=[0.6, 0.3, 0.1])
coordinates = [(1920,1080), (1910, 1000), (1900, 990), (1890, 980)]
for coord in coordinates:
smoothed_value = filter.update(coord)
print(smoothed_value)
\ No newline at end of file
# #coding:utf-8
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
gl_callback = None
# Here's a UDP version of the simplest possible protocol
class EchoUDP(DatagramProtocol):
def datagramReceived(self, datagram, address):
gl_callback(datagram.decode("utf-8"))
# self.transport.loseConnection()
# self.transport.stopListening()
class UdpService():
def start_service(port, callback):
global gl_callback
gl_callback = callback
reactor.listenUDP(port, EchoUDP())
reactor.run(installSignalHandlers = 0)
def stop_service():
reactor.stop()
# -*- coding: utf-8 -*-
import numpy as np
import cv2
from mm_event_mouse import MouseEvent
# from pymouse import PyMouse
from mm_gige import GigeE
from mm_cursor_hider import CursorHider
from win32 import win32api, win32gui, win32print
from win32.lib import win32con
from mm_mouse_filter import WeightedMovingAverageFilter
#import time
gl_cam_running = False
class MouseVideo():
#def start_mouse_follow(callback, pts1, pts2, point_area, video_size, light, show_frame,
# is_mouse_follow, process_ratio, monitor_ratio, is_merge, mousehandler=None):
def start_mouse_follow(callback, pts1, pts2, point_area, video_size, light, show_frame,
is_mouse_follow, process_ratio, monitor_ratio, screen_width, screen_height, mousehandler=None):
filter = WeightedMovingAverageFilter(weights=[0.8,0.1,0.1,0,0], disabled=False, threshold=0.90)
perspective1,maxWidth1,maxHeight1 = MouseVideo.get_perspective(pts1)
perspective2,maxWidth2,maxHeight2 = MouseVideo.get_perspective(pts2)
#hDC = win32gui.GetDC(0)
#main_screen_width = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
#main_screen_height = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
#screen_num = win32api.GetSystemMetrics(win32con.SM_CMONITORS);
#screen_width = main_screen_width if is_merge else main_screen_width * screen_num;
#screen_height = main_screen_height;
#screen_width = screen_size[0]
#screen_height = screen_size[1]
video_width = video_size[0]
video_height = video_size[1]
# mouse = PyMouse()
pX = -1
pY = -1
#error = []
min_area = point_area[0]
max_area = point_area[1]
process = 1
count = 0
cam1 = GigeE.startCamera(0)
cam2 = GigeE.startCamera(1)
if cam1 == None or cam2 == None:
callback(False)
return
#i = 0
callback(True)
#CursorHider.cursor_hider_open()
global gl_cam_running
gl_cam_running = True
while (gl_cam_running):
count = count + process_ratio
if count >= 1:
count = count - 1
img1 = GigeE.GetImage(cam1, video_height, video_width)
img1 = cv2.warpPerspective(img1, perspective1, (maxWidth1, maxHeight1))
img1 = cv2.resize(img1,(round(screen_width/2), screen_height))
img2 = GigeE.GetImage(cam2, video_height, video_width)
img2 = cv2.warpPerspective(img2, perspective2, (maxWidth2, maxHeight2))
img2 = cv2.resize(img2,(round(screen_width/2), screen_height))
img = np.hstack([img1, img2])
#i=i+1
#cv2.imwrite("./img_join/img_join_"+str(i)+'.png',img)
img = cv2.cvtColor(img, cv2.COLOR_BayerBG2BGR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #Color to grayscale))
#sp = img.shape
#frame_height,frame_width = sp[:2]
#img = cv2.medianBlur(img,5) #median filtering
ret,thresh = cv2.threshold(img,light,255,0) #Binarization
image,contours,hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
if show_frame == True:
#cv2.drawContours(img,contours,-1,(255,255,0),15)
new_img = cv2.resize(img,(round(screen_width/2), round(screen_height/2)))
cv2.imshow("mouse_move", new_img)
found_cnt = None
processable = True
for cnt in contours:
area = cv2.contourArea(cnt)
if area <= max_area and area >= min_area:
if found_cnt is not None:
print("error: found multiple point, skip!")
processable = False
break
found_cnt = cnt
#if len(contours) != 1:
# print(len(contours))
if processable == True and found_cnt is not None:
M = cv2.moments(found_cnt)
if M["m00"] != 0:
cX = int(M["m10"]/M["m00"]) #Calculate the centroid
cX = int(cX + (cX - screen_width/2)*monitor_ratio)
#cX = int(cX + (cX - screen_width)*monitor_ratio)
if cX < 0:
cX = 0
if cX > screen_width:
cX = screen_width
cY = int(M["m01"]/M["m00"])
cY = int(cY + (cY - screen_height/2)*monitor_ratio)
#cY = int(cY + (cY - screen_height)*monitor_ratio)
if cY < 0:
cY = 0
if cY > screen_height:
cY = screen_height
if pX != cX or pY != cY:
pX = cX
pY = cY
#print("x:", round(cX*screen_width/frame_width), ", y:", round(cY*screen_height/frame_height))
if is_mouse_follow == True:
points = filter.update((cX, cY))
#MouseEvent.mouse_move(points[0], points[1], main_screen_width, main_screen_height)
if mousehandler is not None:
mousehandler.mouse_move(points[0], points[1])
if cv2.waitKey(10) & 0xFF == ord('q'):
break
GigeE.closeCamera(cam1)
GigeE.closeCamera(cam2)
cv2.destroyAllWindows()
def stop_mouse_follow():
global gl_cam_running
if gl_cam_running == True:
#CursorHider.cursor_hider_close()
gl_cam_running = False
def is_running():
global gl_cam_running
return gl_cam_running
def get_perspective(pts):
rect = MouseVideo.order_points(pts)
(tl, tr, br, bl) = rect
widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2))
widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2))
maxWidth = max(int(widthA), int(widthB))
heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2))
heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2))
maxHeight = max(int(heightA), int(heightB))
dst = np.array([
[0, 0],
[maxWidth - 1, 0],
[maxWidth - 1, maxHeight - 1],
[0, maxHeight - 1]], dtype = "float32")
perspective = cv2.getPerspectiveTransform(rect, dst)
return perspective,maxWidth,maxHeight
def order_points(pts):
rect = np.zeros((4, 2), dtype = "float32")
s = pts.sum(axis = 1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]
diff = np.diff(pts, axis = 1)
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]
return rect
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import imutils
import time
from pymouse import PyMouse
import win32api,win32con
from configparser import ConfigParser
from mm_gige import GigeE
def start_mouse_follow(pts, video_url, point_area, screen_size, video_size, show_frame,
is_mouse_follow, process_ratio, monitor_ratio):
perspective1,maxWidth1,maxHeight1 = get_perspective(pts1)
perspective2,maxWidth2,maxHeight2 = get_perspective(pts2)
#screen_width = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
#screen_height = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
screen_width = screen_size[0]
screen_height = screen_size[1]
video_width = video_size[0]
video_height = video_size[1]
mouse = PyMouse()
pX = -1
pY = -1
#error = []
min_area = point_area[0]
max_area = point_area[1]
process = 1
count = 0
cam1 = GigeE.startCamera(0)
cam2 = GigeE.startCamera(1)
keyValue = 0
i = 0
while keyValue != ord('q'):
count = count + process_ratio
if count >= 1:
count = count - 1
frame1 = GigeE.GetImage(cam1, video_height, video_width)
frame1 = cv2.cvtColor(frame1, cv2.COLOR_BayerBG2BGR)
frame2 = GigeE.GetImage(cam2, video_height, video_width)
frame2 = cv2.cvtColor(frame2, cv2.COLOR_BayerBG2BGR)
i=i+1
cv2.imwrite("./img/img1_"+str(i)+'.png',frame1)
cv2.imwrite("./img/img2_"+str(i)+'.png',frame2)
# cv2.waitKey(10) # time.sleep 延时没有用
keyValue = cv2.waitKey(10)
cv2.destroyAllWindows()
GigeE.closeCamera(cam1)
keyValue = cv2.waitKey()
cv2.destroyAllWindows()
def create_cap(video_url, video_width, video_height):
cap = cv2.VideoCapture(video_url)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, video_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, video_height)
#cap.set(cv2.CAP_PROP_BUFFERSIZE, 3)
#cap.set(cv2.CAP_PROP_FPS, 30)
return cap
def order_points(pts):
rect = np.zeros((4, 2), dtype = "float32")
s = pts.sum(axis = 1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]
diff = np.diff(pts, axis = 1)
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]
return rect
def perspective_transformation(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
dilate = cv2.dilate(blurred, cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)))
# edged = cv2.Canny(dilate, 75, 200)
edged = cv2.Canny(dilate, 30, 120, 3)
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
screen_cnt = None
if len(cnts) > 0:
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4:
screen_cnt = approx
break
return screen_cnt
if __name__ == "__main__":
cf = ConfigParser()
cf.read('config.ini', encoding='utf-8')
show_frame = cf.get('video', 'is_show')
video_size = json.loads(cf.get('video', 'size'))
point_area = json.loads(cf.get('point', 'area'))
point_light = cf.get('point', 'light')
mouse_follow = cf.get('point', 'is_mouse_follow')
fps_ratio = cf.get('point', 'fps_ratio')
monitor_ratio = cf.get('point', 'monitor_ratio')
screen_size = json.loads(cf.get('screen', 'size'))
is_show_frame = int(show_frame) == 1
is_mouse_follow = int(mouse_follow) == 1
process_ratio = float(fps_ratio)
monitor_ratio = float(monitor_ratio)
light = int(point_light)
if process_ratio > 1:
process_ratio = 1
pts1 = np.array(json.loads(cf.get('correct', 'position1')))
pts2 = np.array(json.loads(cf.get('correct', 'position2')))
start_mouse_follow(pts1, pts2, point_area, screen_size, video_size, light,
is_show_frame, is_mouse_follow, process_ratio, monitor_ratio)
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import imutils
from pymouse import PyMouse
import win32api,win32con
from configparser import ConfigParser
from mm_gige import GigeE
import json
import time
def start_mouse_follow(pts1, pts2, point_area, screen_size, video_size, show_frame,
is_mouse_follow, process_ratio, monitor_ratio):
perspective1,maxWidth1,maxHeight1 = get_perspective(pts1)
perspective2,maxWidth2,maxHeight2 = get_perspective(pts2)
#screen_width = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
#screen_height = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
screen_width = screen_size[0]
screen_height = screen_size[1]
video_width = video_size[0]
video_height = video_size[1]
mouse = PyMouse()
pX = -1
pY = -1
#error = []
min_area = point_area[0]
max_area = point_area[1]
process = 1
count = 0
cam1 = GigeE.startCamera(0)
cam2 = GigeE.startCamera(1)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
videoWrite = cv2.VideoWriter(r'./video/v_' + str(time.time()) + r'.mp4',fourcc,24,(screen_width,screen_height), isColor=False)
i = 0
while (True):
count = count + process_ratio
if count >= 1:
count = count - 1
img1=GigeE.GetImage(cam1, video_height, video_width)
img1=cv2.warpPerspective(img1, perspective1, (maxWidth1, maxHeight1))
img1=cv2.resize(img1,(round(screen_width/2), screen_height))
img2=GigeE.GetImage(cam2, video_height, video_width)
img2=cv2.warpPerspective(img2, perspective2, (maxWidth2, maxHeight2))
img2=cv2.resize(img2,(round(screen_width/2), screen_height))
img = np.hstack([img1, img2])
i=i+1
#cv2.imwrite("./img_join/img_join_"+str(i)+'.png',img)
#cv2.drawContours(img,contours,-1,(0,0,0),2)
if show_frame == True:
new_img = cv2.resize(img,(round(screen_width/2), round(screen_height/2)))
cv2.imshow("mouse_move", new_img)
videoWrite.write(img)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
videoWrite.release()
GigeE.closeCamera(cam1)
GigeE.closeCamera(cam2)
cv2.destroyAllWindows()
def get_perspective(pts):
rect = order_points(pts)
(tl, tr, br, bl) = rect
widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2))
widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2))
maxWidth = max(int(widthA), int(widthB))
heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2))
heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2))
maxHeight = max(int(heightA), int(heightB))
dst = np.array([
[0, 0],
[maxWidth - 1, 0],
[maxWidth - 1, maxHeight - 1],
[0, maxHeight - 1]], dtype = "float32")
perspective = cv2.getPerspectiveTransform(rect, dst)
return perspective,maxWidth,maxHeight
def order_points(pts):
rect = np.zeros((4, 2), dtype = "float32")
s = pts.sum(axis = 1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]
diff = np.diff(pts, axis = 1)
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]
return rect
if __name__ == "__main__":
cf = ConfigParser()
cf.read('config.ini', encoding='utf-8')
show_frame = cf.get('video', 'is_show')
video_size = json.loads(cf.get('video', 'size'))
point_area = json.loads(cf.get('point', 'area'))
mouse_follow = cf.get('point', 'is_mouse_follow')
fps_ratio = cf.get('point', 'fps_ratio')
monitor_ratio = cf.get('point', 'monitor_ratio')
screen_size = json.loads(cf.get('screen', 'size'))
is_show_frame = int(show_frame) == 1
is_mouse_follow = int(mouse_follow) == 1
process_ratio = float(fps_ratio)
monitor_ratio = float(monitor_ratio)
if process_ratio > 1:
process_ratio = 1
pts1 = np.array(json.loads(cf.get('correct', 'position1')))
pts2 = np.array(json.loads(cf.get('correct', 'position2')))
start_mouse_follow(pts1, pts2, point_area, screen_size, video_size,
is_show_frame, is_mouse_follow, process_ratio, monitor_ratio)
pip install pymouse
pip install pywin32
pip install opencv-python==3.4.3.18
pip install pyuserinput
pip install imutils
pip install ffmpeg-python
pip install keyboard
pip install comtypes
pip install pycaw
pip install twisted
\ No newline at end of file
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import imutils
from pymouse import PyMouse
import win32api,win32con
from configparser import ConfigParser
from mm_gige import GigeE
import json
import time
def start_mouse_follow(pts1, pts2, point_area, screen_size, video_size, show_frame,
is_mouse_follow, process_ratio, monitor_ratio):
perspective1,maxWidth1,maxHeight1 = get_perspective(pts1)
perspective2,maxWidth2,maxHeight2 = get_perspective(pts2)
#screen_width = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
#screen_height = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
screen_width = screen_size[0]
screen_height = screen_size[1]
video_width = video_size[0]
video_height = video_size[1]
mouse = PyMouse()
pX = -1
pY = -1
#error = []
min_area = point_area[0]
max_area = point_area[1]
process = 1
count = 0
cam1 = GigeE.startCamera(0)
cam2 = GigeE.startCamera(1)
i = 0
while (True):
count = count + process_ratio
if count >= 1:
count = count - 1
img1 = GigeE.GetImage(cam1, video_height, video_width)
img1 = cv2.warpPerspective(img1, perspective1, (maxWidth1, maxHeight1))
img1 = cv2.resize(img1,(round(screen_width/2), screen_height))
img2 = GigeE.GetImage(cam2, video_height, video_width)
img2 = cv2.warpPerspective(img2, perspective2, (maxWidth2, maxHeight2))
img2 = cv2.resize(img2,(round(screen_width/2), screen_height))
img = np.hstack([img1, img2])
img = cv2.cvtColor(img, cv2.COLOR_BayerBG2BGR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #Color to grayscale))
#sp = img.shape
#frame_height,frame_width = sp[:2]
#img = cv2.medianBlur(img,5) #median filtering
ret,thresh = cv2.threshold(img,20,255,0) #Binarization
image,contours,hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img,contours,-1,(255,255,0),15)
img = cv2.resize(img,(round(screen_width/2), round(screen_height/2)))
cv2.imshow("mouse_move", img)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
GigeE.closeCamera(cam1)
GigeE.closeCamera(cam2)
cv2.destroyAllWindows()
def get_perspective(pts):
rect = order_points(pts)
(tl, tr, br, bl) = rect
widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2))
widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2))
maxWidth = max(int(widthA), int(widthB))
heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2))
heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2))
maxHeight = max(int(heightA), int(heightB))
dst = np.array([
[0, 0],
[maxWidth - 1, 0],
[maxWidth - 1, maxHeight - 1],
[0, maxHeight - 1]], dtype = "float32")
perspective = cv2.getPerspectiveTransform(rect, dst)
return perspective,maxWidth,maxHeight
def order_points(pts):
rect = np.zeros((4, 2), dtype = "float32")
s = pts.sum(axis = 1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]
diff = np.diff(pts, axis = 1)
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]
return rect
if __name__ == "__main__":
cf = ConfigParser()
cf.read('config.ini', encoding='utf-8')
show_frame = cf.get('video', 'is_show')
video_size = json.loads(cf.get('video', 'size'))
point_area = json.loads(cf.get('point', 'area'))
mouse_follow = cf.get('point', 'is_mouse_follow')
fps_ratio = cf.get('point', 'fps_ratio')
monitor_ratio = cf.get('point', 'monitor_ratio')
screen_size = json.loads(cf.get('screen', 'size'))
is_show_frame = int(show_frame) == 1
is_mouse_follow = int(mouse_follow) == 1
process_ratio = float(fps_ratio)
monitor_ratio = float(monitor_ratio)
if process_ratio > 1:
process_ratio = 1
pts1 = np.array(json.loads(cf.get('correct', 'position1')))
pts2 = np.array(json.loads(cf.get('correct', 'position2')))
start_mouse_follow(pts1, pts2, point_area, screen_size, video_size,
is_show_frame, is_mouse_follow, process_ratio, monitor_ratio)
差异被折叠。 点击展开。
# -*- coding: utf-8 -*-
import numpy as np
import cv2
import imutils
from pymouse import PyMouse
import win32api,win32con
from configparser import ConfigParser
import json
import ctypes
import tkinter
from tkinter import *
from tkinter import ttk
import subprocess,os
from threading import Thread
def show_win():
command = 'reg add "HKCU\Control Panel\Cursors" /f /ve /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Scheme Source" /t REG_DWORD /d 0\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Arrow" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Help" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "AppStarting" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Wait" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Crosshair" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "IBeam" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "NWPen" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "No" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNS" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeWE" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNWSE" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeNESW" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "SizeAll" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "UpArrow" /t REG_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Person" /t REG_EXPAND_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Hand" /t REG_EXPAND_SZ /d ""\
&& reg add "HKCU\Control Panel\Cursors" /f /v "Pin" /t REG_EXPAND_SZ /d ""\
&& reg delete "HKCU\Control Panel\Cursors\Schemes" /f /v "videomouse"'
os.system(command)
dll = ctypes.windll.LoadLibrary('user32')
dll.SystemParametersInfoW(87,0,0,2)
if __name__ == "__main__":
show_win()
from win32 import win32api, win32gui, win32print
from win32.lib import win32con
from mm_event_mouse import MouseEvent
#MouseEvent.test()
hDC = win32gui.GetDC(0)
main_screen_width = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
main_screen_height = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
print(main_screen_width, main_screen_height);
#MouseEvent.mouse_move(-2860, 800, main_screen_width, main_screen_height)
count = win32api.GetSystemMetrics(win32con.SM_CMONITORS);
print(count);
\ No newline at end of file
@echo off
@echo off
python print_video.py
\ No newline at end of file
@echo off
@echo off
python print_img.py
\ No newline at end of file
@echo off
@echo off
python start.py
\ No newline at end of file
@echo off
@echo off
python stop_cursor.py
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论