我刚买了一台FLIR BlackFlyS USB3.0相机。我可以从摄像头中抓取帧,但如果不先保存它们,我就不能在opencv中使用该帧。有没有人知道如何将它们转换为在opencv中使用?
我在网上搜索了所有包含"PySpin“的单词,找到了this book。我试过使用本书中提到的PySpinCapture,但无论如何我都不能理解它。
capture = PySpinCapture.PySpinCapture(0, roi=(0, 0, 960, 600),binningRadius=2,isMonochrome=True)
ret, frame = capture.read()
cv2.imshow("image",frame)
cv2.waitKey(0)我希望看到图像,但它抛出了一个错误
_PySpin.SpinnakerException: Spinnaker: GenICam::AccessException= Node is not writable. : AccessException thrown in node 'PixelFormat' while calling 'PixelFormat.SetIntValue()' (file 'EnumerationT.h', line 83) [-2006]
terminate called after throwing an instance of 'Spinnaker::Exception'发布于 2020-07-18 21:42:07
一年后,我不确定我的响应是否会有帮助,但我发现您可以通过使用GetData()函数从PySpin图像中获取RGB数组。
因此,您可以不使用PySpinCapture模块,只需执行以下操作即可。
import PySpin
import cv2
serial = '18475994' #Probably different for you although I also use a BlackFly USB3.0
system = PySpin.System.GetInstance()
blackFly_list = system.GetCameras()
blackFly = blackFly_list.GetBySerial(serial)
height = blackFly.Height()
width = blackFly.Width()
channels = 1
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('test_vid.avi',fourcc, blackFly.AcquisitionFrameRate(), (blackFly.Width(), blackFly.Height()), False) #The last argument should be True if you are recording in color.
blackFly.Init()
blackFly.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
blackFly.BeginAcquisition()
nFrames = 1000
for _ in range(nFrames):
im = blackFly.GetNextImage()
im_cv2_format = im.GetData().reshape(height,width,channels)
# Here I am writing the image to a Video, but once you could save the image as something and just do whatever you want with it.
out.write(im_cv2_format)
im.release()
out.release() 在此代码示例中,我想创建一个具有1000个抓取帧的AVI视频文件。im.GetData()返回一个一维numpy数组,然后可以通过重塑将其转换为正确的维数。我看过一些关于使用UMat类的讨论,但似乎没有必要让它在这种情况下工作。也许它有助于提高性能,但我不确定:)
https://stackoverflow.com/questions/56687029
复制相似问题