Python OpenCV拍摄的显微镜图像解码问题
我正在尝试使用OpenCV从一台计算机上捕获图像。它在手册中说,它可以使用USB3.0电缆插入计算机,然后用作普通网络摄像头 因此,我使用这个非常简单的片段从相机中捕获图像:Python OpenCV拍摄的显微镜图像解码问题,python,opencv,camera,vlc,Python,Opencv,Camera,Vlc,我正在尝试使用OpenCV从一台计算机上捕获图像。它在手册中说,它可以使用USB3.0电缆插入计算机,然后用作普通网络摄像头 因此,我使用这个非常简单的片段从相机中捕获图像: 导入cv2 摄像机=cv2。视频捕获(0) ret,frame=camera.read() 如果ret: cv2.imwrite('./test.png',框架) 然而,当我应该得到1920像素x 1080像素的RGB图片时,我得到的是带有奇怪伪影的640像素x 480像素的图片: 我尝试在其他软件上测试相机,如VLC
导入cv2
摄像机=cv2。视频捕获(0)
ret,frame=camera.read()
如果ret:
cv2.imwrite('./test.png',框架)
然而,当我应该得到1920像素x 1080像素的RGB图片时,我得到的是带有奇怪伪影的640像素x 480像素的图片:
我尝试在其他软件上测试相机,如VLC或AMCap,但我得到的不是640px x 480px
黑色图像,就是软件甚至无法启动捕获
我想知道这是否是一个编码问题,或者是关于相机如何向计算机声明自己的问题
我可以通过修改OpenCV中的一些参数来解决这个问题吗?或者是有什么不同
非常感谢您抽出时间
编辑1:
my conda环境中opencv_版本-v的输出:
General configuration for OpenCV 3.4.2 =====================================
Version control: unknown
Extra modules:
Location (extra): /opt/conda/conda-bld/opencv-suite_1533641454250/work/opencv_contrib-3.4.2/modules
Version control (extra): unknown
Platform:
Timestamp: 2018-08-07T11:32:43Z
Host: Linux 2.6.32-696.10.1.el6.x86_64 x86_64
CMake: 3.12.0
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (3 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (9 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX
C/C++:
Built as dynamic libs?: YES
C++11: YES
C++ Compiler: /opt/conda/conda-bld/opencv-suite_1533641454250/_build_env/bin/x86_64-conda_cos6-linux-gnu-c++ (ver 7.2.0)
C++ flags (Release): -fvisibility-inlines-hidden -std=c++11 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/home/lucas/anaconda3/envs/p35_gpu_jupyter/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fopenmp -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fvisibility-inlines-hidden -std=c++11 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/home/lucas/anaconda3/envs/p35_gpu_jupyter/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fopenmp -g -DDEBUG -D_DEBUG
C Compiler: /opt/conda/conda-bld/opencv-suite_1533641454250/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc
C flags (Release): -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/home/lucas/anaconda3/envs/p35_gpu_jupyter/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fopenmp -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/home/lucas/anaconda3/envs/p35_gpu_jupyter/include -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=${PREFIX}=/usr/local/src/conda-prefix -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fopenmp -g -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/home/lucas/anaconda3/envs/p35_gpu_jupyter/lib -L/home/lucas/anaconda3/envs/p35_gpu_jupyter/lib
Linker flags (Debug): -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/home/lucas/anaconda3/envs/p35_gpu_jupyter/lib -L/home/lucas/anaconda3/envs/p35_gpu_jupyter/lib
ccache: NO
Precompiled headers: YES
Extra dependencies: dl m pthread rt
3rdparty dependencies:
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc java java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: js world
Disabled by dependency: -
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv matlab ovis sfm ts viz
Applications: apps
Documentation: NO
Non-free algorithms: NO
GUI:
Media I/O:
ZLib: /home/lucas/anaconda3/envs/p35_gpu_jupyter/lib/libz.so (ver 1.2.11)
JPEG: /home/lucas/anaconda3/envs/p35_gpu_jupyter/lib/libjpeg.so (ver 90)
WEBP: build (ver encoder: 0x020e)
PNG: /home/lucas/anaconda3/envs/p35_gpu_jupyter/lib/libpng.so (ver 1.6.34)
TIFF: /home/lucas/anaconda3/envs/p35_gpu_jupyter/lib/libtiff.so (ver 42 / 4.0.9)
JPEG 2000: /home/lucas/anaconda3/envs/p35_gpu_jupyter/lib/libjasper.so (ver 2.0.14)
OpenEXR: build (ver 1.7.1)
HDR: YES
SUNRASTER: YES
PXM: YES
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (ver 58.18.100)
avformat: YES (ver 58.12.100)
avutil: YES (ver 56.14.100)
swscale: YES (ver 5.1.100)
avresample: YES (ver 4.0.0)
GStreamer: NO
libv4l/libv4l2: NO
v4l/v4l2: linux/videodev.h linux/videodev2.h
gPhoto2: NO
Parallel framework: OpenMP
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2017.0.3 [2017.0.3]
at: /opt/conda/conda-bld/opencv-suite_1533641454250/work/build/3rdparty/ippicv/ippicv_lnx
Intel IPP IW: sources (2017.0.3)
at: /opt/conda/conda-bld/opencv-suite_1533641454250/work/build/3rdparty/ippicv/ippiw_lnx
Lapack: NO
Eigen: YES (ver 3.3.3)
Custom HAL: NO
Protobuf: /home/lucas/anaconda3/envs/p35_gpu_jupyter/lib/libprotobuf.so (3.5.1)
Python 2:
Interpreter: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py2/bin/python (ver 2.7.15)
Libraries: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py2/lib/libpython2.7m.so (ver 2.7.15)
numpy: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py2/lib/python2.7/site-packages/numpy/core/include (ver 1.11.3)
packages path: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py2/lib/python2.7/site-packages
Python 3:
Interpreter: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py3/bin/python (ver 3.7)
Libraries: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py3/lib/libpython3.7m.so (ver 3.7.0)
numpy: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py3/lib/python3.7/site-packages/numpy/core/include (ver 1.11.3)
packages path: /opt/conda/conda-bld/opencv-suite_1533641454250/work/py3/lib/python3.7/site-packages
Python (for build): /opt/conda/conda-bld/opencv-suite_1533641454250/work/py2/bin/python
Java:
ant: /usr/bin/ant (ver 1.7.1)
JNI: /usr/lib/jvm/java/include /usr/lib/jvm/java/include/linux /usr/lib/jvm/java/include
Java wrappers: YES
Java tests: NO
Install to: /home/lucas/anaconda3/envs/p35_gpu_jupyter
-----------------------------------------------------------------
不同类型的USB传输
您引用的页面没有说明该设备可以“使用USB 3.0电缆插入计算机,然后用作普通网络摄像头”。页面上只说它有一个usb 3.0接口。您所引用的页面上唯一可用的资源是手册,其中也没有说明其即插即用功能
在视觉设备和成像设备领域,usb之上的通用接口是。制造此类设备的供应商提供专门的驱动程序,并通常提供有关如何与流行库(如openCV)接口的示例代码。与即插即用相比,使用符合此标准的设备可以提高传输速率、减少延迟时间和降低cpu利用率。通常,还提供了即插即用驱动程序,但您无法保证。如果除了usb vision之外还可以使用这种即插即用驱动程序,那么您可能希望改用usb vision驱动程序,因为它很可能会更优越
事实上,销售商没有说它是什么司机,这让我立即产生怀疑。我会在购买之前联系他们,让他们解释为什么没有提到这一点(或者可能是隐藏在他们网页的某个地方?)
在linux上(在评论中你说你运行的是Ubuntu18.04),这种即插即用功能是通过linux“v4l”视频实现的。如果您想使用如上所示的设备,则需要确保供应商提供适用于您的Linux版本的v4l驱动程序
Ubuntu版本
在写这篇文章时(2018年11月19日),Ubuntu 18.04还没有出现足够长的时间来期待非通用用例的稳定性。如果该成像设备的供应商提供v4l接口驱动程序,则它很可能不稳定。如果可能的话,尝试使用Ubuntu 16。如果您发现它可以与Ubuntu 16一起使用,即使您的驱动程序应该为Ubuntu 18工作,请务必通知开发人员您发现了一个bug。TL;DR使用的电缆是USB 2.0,用USB 3.0代替它解决了Windows上的捕获问题。
是的,我知道这听起来很愚蠢,但我得到这个奇怪图像的原因是USB电缆是2.0而不是3.0。由于电缆已经插入相机,我没有费心验证它,但将其更改为3.0使其立即在相机Windows应用程序上工作。该公司还确认EVO Cam II使用DirectShow格式生成信号
然而,当比较相机保存在USB驱动器上的图像和使用USB电缆捕获的图像时,我意识到质量并不相似。特别是在我的例子中,使用USB电缆拍摄的图像质量不够好。因此,我将不再朝这个方向努力
但是,对于那些想继续我留下的内容的人,这里有一些Vision Engineering support为我提供的在Linux上使用OpenCV捕获图像的链接:
目前他们还没有一个简单的解决方案。它连接到哪台计算机?Mac、Linux、Raspbian、Windows?你试过使用记忆棒吗?您是将电缆连接到侧面还是背面?您应该咨询视觉工程的技术支持。@MarkSetchell,图片来自linux计算机(Ubuntu 18.04)。Opencv无法在macOs上初始化相机。我可以毫无问题地将图片保存到usb,并且可以使用内置HDMI电缆在屏幕上显示视频。我把相机附带的电缆连接到了后面。@YvesDaoust我问过视觉工程的技术支持,但我还没有得到他们的回复。应该有一个可执行文件,你可以在其中创建名为OpenCV\u version
的OpenCV,试着用OpenCV\u version-v
运行它,看看你安装了什么视频编解码器。我联系了他们,他们回答说EVO Cam II使用DirectShow格式生成信号。DirectShow适用于windows。询问他们关于Linux驱动程序的情况。特别是,如果它使用V4L。(除非你现在使用的是windows系统,你原来的帖子说的是ubuntu)@LucasVandroux,问“我的ubuntu X.X.X版本笔记本电脑上的v4l(linux视频)摄像头有问题吗?”如果他们说有,那么问他们一个gstreamer接口示例。这些是“gst启动”命令,您可以从命令行轻松运行。。。并且应该在独立窗口中弹出视频或静像。如果这样做有效,那么从那里继续。。。在你的机器上安装之前,不要做其他事情。。。。不管怎样,这是我的建议非常感谢你的建议,正如我在回答中提到的,相机没有Linux驱动程序,这是他们给我的解决方案