建设企业外贸网站,芜湖建设公司网站,西安seo托管,界面设计是什么安装cmake
打开cmake官网 https://cmake.org/download/#xff0c;下载安装包#xff1a; 安装时选择将cmake加到系统环境变量里。安装完成后在新的CMD命令窗口执行cmake --version可看到输出#xff1a;
D:\cmake --version
cmake version 3.29.3
CMake suite mainta…安装cmake
打开cmake官网 https://cmake.org/download/下载安装包 安装时选择将cmake加到系统环境变量里。安装完成后在新的CMD命令窗口执行cmake --version可看到输出
D:\cmake --version
cmake version 3.29.3
CMake suite maintained and supported by Kitware (kitware.com/cmake). 安装Mingw64 GCC
Mingw目标是为支持Windows平台上的GCC编译它主要提供头文件和支持库Mingw自身不包括GCC和binutils所以官网提供了集成这些组件的各种安装包。列表里有Linux平台的安装包那些是用来在Linux平台生成Widows程序的。
https://www.mingw-w64.org/ 这里我选择了w64devkit点击后安装链接指向了githubhttps://github.com/skeeto/w64devkit/releases 下载w64devkit-1.23.0.zip。 解压后放在C盘将目录 C:\w64devkit\bin\ 加入系统PATH环境变量。 然后新打开的CMD命令窗口输入gcc –v 可以看到输出
D:\gcc -v
Using built-in specs.
COLLECT_GCCgcc
COLLECT_LTO_WRAPPERC:/w64devkit/bin/../libexec/gcc/x86_64-w64-mingw32/14.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: /gcc-14.1.0/configure --prefix/w64devkit --with-sysroot/w64devkit/x86_64-w64-mingw32 --with-native-system-header-dir/include --targetx86_64-w64-mingw32 --hostx86_64-w64-mingw32 --enable-static --disable-shared --with-pic --with-gmp-include/deps/include --with-gmp-lib/deps/lib --with-mpc-include/deps/include --with-mpc-lib/deps/lib --with-mpfr-include/deps/include --with-mpfr-lib/deps/lib --enable-languagesc,c --enable-libgomp --enable-threadsposix --enable-version-specific-runtime-libs --disable-dependency-tracking --disable-lto --disable-multilib --disable-nls --disable-win32-registry --enable-mingw-wildcard CFLAGS_FOR_TARGET-Os CXXFLAGS_FOR_TARGET-Os LDFLAGS_FOR_TARGET-s CFLAGS-Os CXXFLAGS-Os LDFLAGS-s
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.1.0 (GCC) 下载libusb
Libuvc依赖libusblibusb是一个低级的通用访问USB设备的用户空间库。我们直接下载官网已经编译好的二进制库。
https://libusb.info/ 点击图中Latest Windows Binaries下载 https://github.com/libusb/libusb/releases/download/v1.0.27/libusb-1.0.27.7z 解压后将 include\libusb.h, MinGW64下面的 .a 及 .dll 库提取到一个目录如D:\libusb: 下载编译libuvc
https://github.com/libuvc/libuvc
从官网以git clone下载源码源码所放位置为D:\libuvc 由于cmake最小版本过低会产生如下告警
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):Compatibility with CMake 3.5 will be removed from a future version ofCMake.Update the VERSION argument min value or use a ...max suffix to tellCMake that the project does not need compatibility with older versions.
所以我们把libuvc/CmakeList.txt开头的cmake最低版本改为3.10 如果直接执行cmake .. 会提示找不到libusb打开D:\libuvc\CmakeLists.txt删除find_package(LibUSB)一行替换为下面内容目录分隔符这里用的是 / 如果用 \ 分隔转义的原因还要改为 \\
# Locate the libusb-1.0 package manually if not found
#find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h PATH_SUFFIXES libusb-1.0)
#find_library(LIBUSB_LIBRARY NAMES usb-1.0 libusb-1.0)
set(LIBUSB_INCLUDE_DIR D:/libusb)
set(LIBUSB_LIBRARY D:/libusb/libusb-1.0.dll D:/libusb/libusb-1.0.dll.a)
#set(LIBUSB_LIBRARY D:/libusb/libusb-1.0.a) # for static linkif(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARY)set(LIBUSB_FOUND TRUE)
else()set(LIBUSB_FOUND FALSE)message(WARNING LibUSB not found. Please install it.)
endif() 静态链接用lbusb-1.0.a就注释掉46行打开47行 这样会更方便一点不会产生找不到dll的问题。 然后在130行左右添加libusb.h头文件目录和链接库 打开CMD窗口执行下面命令
cd D:\libuvc
mkdir build install
cd build
rm –fr *; #如果cmake有错重新执行时建议把目录清空。
cmake -G MinGW Makefiles -DCMAKE_INSTALL_PREFIXD:\libuvc\install -DBUILD_SHARED_LIBSON ..
第一次执行cmake报错, 系统会报病毒拦截再执行一次上面的cmake 命令即可。 不确定是误报还是真有病毒。
CMake Error at C:/Program Files/CMake/share/cmake-3.29/Modules/CMakeDetermineCompilerId.cmake:922 (file):file STRINGS file D:/libuvc/build/CMakeFiles/3.29.3/CompilerIdC/a.execannot be read. 执行cmake成功后生成Makefie接下来执行make命令进行编译。编译过程中会提示ARRAYSIZE重复定义的警告:
D:/libuvc/include/libuvc/libuvc_internal.h:75:9: warning: ARRAYSIZE redefined75 | #define ARRAYSIZE(arr) (sizeof(arr) / (IS_ARRAY(arr) ? sizeof(arr[0]) : 0))| ^~~~~~~~~
In file included from C:/w64devkit/x86_64-w64-mingw32/include/minwindef.h:163,from C:/w64devkit/x86_64-w64-mingw32/include/windef.h:9,from C:/w64devkit/x86_64-w64-mingw32/include/windows.h:69,from D:/libusb/libusb.h:64,from D:/libuvc/include/libuvc/libuvc_internal.h:14:
C:/w64devkit/x86_64-w64-mingw32/include/winnt.h:681:
note: this is the location of the previous definition681 | #define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
如果不想看到太多输出警告信息可以编辑D:\libuvc\include\libuvc\libuvc_internal.h 在ARRAYSIZE外面加上#ifndef ARRAYSIZE 进行防御。 编译成功
D:\libuvc\buildmake
[ 5%] Building C object CMakeFiles/uvc.dir/src/ctrl.c.obj
[ 10%] Building C object CMakeFiles/uvc.dir/src/ctrl-gen.c.obj
[ 15%] Building C object CMakeFiles/uvc.dir/src/device.c.obj
[ 20%] Building C object CMakeFiles/uvc.dir/src/diag.c.obj
[ 25%] Building C object CMakeFiles/uvc.dir/src/frame.c.obj
[ 30%] Building C object CMakeFiles/uvc.dir/src/init.c.obj
[ 35%] Building C object CMakeFiles/uvc.dir/src/stream.c.obj
[ 40%] Building C object CMakeFiles/uvc.dir/src/misc.c.obj
[ 45%] Linking C shared library libuvc.dll
[ 45%] Built target uvc
[ 50%] Building C object CMakeFiles/uvc_static.dir/src/ctrl.c.obj
[ 55%] Building C object CMakeFiles/uvc_static.dir/src/ctrl-gen.c.obj
[ 60%] Building C object CMakeFiles/uvc_static.dir/src/device.c.obj
[ 65%] Building C object CMakeFiles/uvc_static.dir/src/diag.c.obj
[ 70%] Building C object CMakeFiles/uvc_static.dir/src/frame.c.obj
[ 75%] Building C object CMakeFiles/uvc_static.dir/src/init.c.obj
[ 80%] Building C object CMakeFiles/uvc_static.dir/src/stream.c.obj
[ 85%] Building C object CMakeFiles/uvc_static.dir/src/misc.c.obj
[ 90%] Linking C static library libuvc.a
[ 90%] Built target uvc_static
[ 95%] Building C object CMakeFiles/example.dir/src/example.c.obj
[100%] Linking C executable example.exe
[100%] Built target example
然后安装到install目录
D:\libuvc\buildmake install
[ 45%] Built target uvc
[ 90%] Built target uvc_static
[100%] Built target example
Install the project...
-- Install configuration: Release
-- Installing: D:/libuvc/install/lib/libuvc.dll.a
-- Installing: D:/libuvc/install/bin/libuvc.dll
-- Installing: D:/libuvc/install/include/libuvc/libuvc.h
-- Installing: D:/libuvc/install/include/libuvc/libuvc_config.h
-- Installing: D:/libuvc/install/lib/libuvc.a
-- Up-to-date: D:/libuvc/install/include/libuvc/libuvc.h
-- Up-to-date: D:/libuvc/install/include/libuvc/libuvc_config.h
-- Installing: D:/libuvc/install/lib/cmake/libuvc/libuvcTargets.cmake
-- Installing: D:/libuvc/install/lib/cmake/libuvc/libuvcTargets-release.cmake
-- Installing: D:/libuvc/install/lib/cmake/libuvc/FindLibUSB.cmake
-- Installing: D:/libuvc/install/lib/cmake/libuvc/FindJpegPkg.cmake
-- Installing: D:/libuvc/install/lib/cmake/libuvc/libuvcConfigVersion.cmake
-- Installing: D:/libuvc/install/lib/pkgconfig/libuvc.pc
-- Installing: D:/libuvc/install/lib/cmake/libuvc/libuvcConfig.cmake 测试
以example.exe来进行测试。
首先利用USBDeview (https://usbdeview.me)工具找到电脑上外置UVC摄像头的VID和PID。 然后打开D:\libuvc\src\example.c 修改其中的VID和PID 重新在build目录执行make然后执行example.exe, 会提示找不到libusb-1.0.dll可以将D:\libusb-1.0.dll复制一份放在example.exe同一个目录。 或者一劳永逸的复制到C:\Windows\System32下。 如果给别人发编译好的程序需要带上libusb-1.0.dll。若前面Cmake配置静态链接libusb则没有此麻烦。 解决完dll问题后example跑起来会报错找不到设备
D:\libuvc\buildexample.exe
UVC initialized
Device found
uvc_open: Not found (-5)
UVC exited
先用USBDeview查看驱动此UVC设备使用了usbvideo驱动需要安装WinUSB驱动。 https://learn.microsoft.com/zh-cn/windows-hardware/drivers/usbcon/winusb-installation 面向开发人员的 WinUSB (Winusb.sys) 安装 文档中描述到
对于某些通用串行总线 (USB) 设备例如仅由单个应用程序访问的设备可以在设备的内核模式堆栈中安装 WinUSB (Winusb.sys) 作为 USB 设备的功能驱动程序而不是实现驱动程序。libusb正是此种场景。可以认为WinUSB.sys驱动是一种低层次的驱动libusb要跟低层的驱动打交道usbvideo.sys驱动是高层次的驱动。可以31按链接中微软官方的指导安装WinUSB驱动也可以用Zadig来安装此驱动。 从 https://zadig.akeo.ie下载Zadig。由于在此电脑上USB Camera(Interface 0)是Video类型USB Camera(Interface 2)是Audio类型 所以在从Options菜单中选择List All Devices后选择USB Camera(Interface 0)换用WinUSB驱动。 安装WinUSB驱动后用USBDeview查看 example跑成功的日志
D:\libuvc\buildexample.exeUVC initialized
Device found
Device openedDEVICE CONFIGURATION (b349:b182/[none]) ---
Status: idle
VideoControl:bcdUVC: 0x0100VideoStreaming(1):bEndpointAddress: 129Formats:UncompressedFormat(1)bits per pixel: 16GUID: 5955593200001000800000aa00389b71 (YUY2)default frame: 1aspect ratio: 0x0interlace flags: 00copy protect: 00FrameDescriptor(1)capabilities: 01size: 1600x1200bit rate: 153600000-153600000max frame size: 3840000default interval: 1/5interval[0]: 1/5FrameDescriptor(2)capabilities: 01size: 1280x720bit rate: 110592000-110592000max frame size: 1843200default interval: 1/7interval[0]: 1/7FrameDescriptor(3)capabilities: 01size: 640x480bit rate: 147456000-147456000max frame size: 614400default interval: 1/30interval[0]: 1/30MJPEGFormat(2)bits per pixel: 0GUID: 4d4a5047000000000000000000000000 (MJPG)default frame: 1aspect ratio: 0x0interlace flags: 00copy protect: 00FrameDescriptor(1)capabilities: 01size: 1600x1200bit rate: 921600000-921600000max frame size: 3840000default interval: 1/30interval[0]: 1/30FrameDescriptor(2)capabilities: 01size: 1280x720bit rate: 442368000-442368000max frame size: 1843200default interval: 1/30interval[0]: 1/30FrameDescriptor(3)capabilities: 01size: 640x480bit rate: 147456000-147456000max frame size: 614400default interval: 1/30interval[0]: 1/30
END DEVICE CONFIGURATION
First format: (YUY2) 1600x1200 5fps
bmHint: 0001
bFormatIndex: 1
bFrameIndex: 1
dwFrameInterval: 2000000
wKeyFrameRate: 0
wPFrameRate: 0
wCompQuality: 61
wCompWindowSize: 0
wDelay: 0
dwMaxVideoFrameSize: 3840000
dwMaxPayloadTransferSize: 3060
bInterfaceNumber: 1
Streaming...
Enabling auto exposure ...... full AE not supported, trying aperture priority mode... enabled aperture priority auto exposure mode
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
callback! frame_format 3, width 1600, height 1200, length 3840000, ptr 0000000000003039
Done streaming.
Device closed
UVC exited 恢复驱动
安装过WinUSB驱动的UVC设备不会出现在设备管理器的照像机下面。 如果要恢复正常的UVC Camera功能可以在设备管理器中卸载此设备的驱动。 卸载驱动后在设备管理器中右击鼠标扫描检测硬件改动USB Camera可以自动识别出来。驱动也恢复为原来的usbvideo.sys。