我正在尝试使用 opencv python 捕获 GigE 视觉相机图像。我阅读了一些有关使用 Baumer GAPI SDK 和 c++ 捕获图像的问题这里。我是一名python程序员,我想问是否可以为python实现相同的方法。 我在 Baumer 网站上阅读了另一篇关于将图像从 Baumer GAPI 传输到 OpenCV c++ 的教程 这里
您需要在 GiGE 支持下从源代码构建 Opencv。 或者使用支持 GiGE 的外部 python 库,例如: https://github.com/genicam/harvesters
我正在尝试做同样的事情。我曾经使用 Matlab 图像采集工具,但它对于我的 20 mpx 相机来说存在一些性能问题。所以我从 Baumer 转向 neoAPI,它就像魔法一样工作。
下载 Baumer SDK - 您已经拥有了
下载适合您的机器和操作系统的 API https://www.baumer.com/us/en/product-overview/industrial-cameras-image-processing/software/baumer-neoapi/c/42528
安装 *.whl 文件,对我来说是:
pip安装baumer_neoapi-1.4.1-cp34.cp35.cp36.cp37.cp38.cp39.cp310.cp311.cp312-none-win_amd64.whl
然后启动连接:
import neoapi
import cv2
import time
import matplotlib.pyplot as plt
camera = neoapi.Cam()
camera.Connect('700005420355')
#It can be name, or serial number, or ip adress of your camera
camera.f.ExposureTime.Set(20537)
camera.DisableChunk()
camera.SetImageBufferCount()
camera.SetImageBufferCycleCount()
try:
camera.f.PixelFormat.Set(neoapi.PixelFormat_BGR8)
print("using RGB")
except neoapi.FeatureAccessException:
camera.f.PixelFormat.Set(neoapi.PixelFormat_Mono8)
camera.f.TriggerMode.value = neoapi.TriggerMode_On
这会将相机设置为软件触发,因此为了拍摄图像,您必须使用另一个脚本。我使用的是高分辨率相机,所以 fps 很低,所以我必须等到图像通过以太网发送到 PC:
camera.f.TriggerSoftware.Execute()
i = camera.GetImage()
while i.IsEmpty():
time.sleep(0.1)
i = camera.GetImage()
# get the meta data from the image
if not i.IsEmpty():
print(i.GetImageID())
print(i.GetTimestamp())
print(i.GetSize())
print(i.GetPixelFormat())
npimg=i.GetNPArray()
plt.imshow(npimg)
cv2.imwrite('output.png', npimg)
我希望这会有所帮助。