windows系统电脑、basler相机(GIge接口)、路由器、Python编程环境(之前的帖子有安装步骤)
1.首先利用官网自带的软件调试通相机,软件下载地址:/cn/sales-support/downloads/software-downloads/#type=pylonsoftware;version=all;os=windows;series=baslerace;model=all根据自己的系统型号下载对应的软件安装好。
2.将电脑和相机利用路由器连接在同一个局域网内,打开软件先选择Tools,搜索相机IP并改成固定IP。
之后就可以看到相机的实时图像了,该软件可以现实图像的保存,调相机参数等。
3.利用Python进行二次开发,先下载opencv,pypylon模块,这个是新出的调试该相机的python包。
具体代码:
from pypylon import pylon
import cv2
# conecting to the first available camera
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
# Grabing Continusely (video) with minimal delay
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
converter = pylon.ImageFormatConverter()
# converting to opencv bgr format
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
while camera.IsGrabbing():
grabResult = camera.RetrieveResult(1000, pylon.TimeoutHandling_ThrowException)
if grabResult.GrabSucceeded():
# Access the image data
image = converter.Convert(grabResult)
img = image.GetArray()
cv2.namedWindow('title', cv2.WINDOW_NORMAL)
cv2.imshow('title', img)
k = cv2.waitKey(1)
if k == 27:
break
grabResult.Release()
# Releasing the resource
camera.StopGrabbing()
cv2.destroyAllWindows()
效果图:(运行代码时,要先关闭之前的软件,不然会有冲突)