简体   繁体   English

如何在python中使用Spinnaker从点灰色相机获取彩色图像?

[英]How to get color image from point grey camera with Spinnaker in python?

I am trying to get color images (no difference in rgb or bgr in my case) from flea3 camera (with the code "FL3-U3-32S2C-CS", which shows its a color camera) but my code generates grayscale photos... what is wrong in the following code snippet?我正在尝试从 flea3 相机(代码为“FL3-U3-32S2C-CS”,显示其为彩色相机)获取彩色图像(在我的情况下 rgb 或 bgr 没有区别),但我的代码生成灰度照片.. . 下面的代码片段有什么问题? any idea?任何想法?

    #  Begin acquiring images
    cam.BeginAcquisition()

    #  Retrieve next image and convert it
    image_result = cam.GetNextImage()
    img_converted = image_result.Convert(PySpin.PixelFormat_RGB8, PySpin.HQ_LINEAR)

    #  Convert the Image object to RGB array
    width = image_result.GetWidth()
    height = image_result.GetHeight()
    rgb_array = img_converted.GetData()
    rgb_array = rgb_array.reshape(height, width, 3)

I had the same issue but with a Blackfly S camera over USB.我有同样的问题,但通过 USB 使用 Blackfly S 相机。 I had to use a specific format to get it to work.我必须使用特定的格式才能使其工作。 I also set the pixel format on the camera before acquisition.我还在采集前在相机上设置了像素格式。

cam.PixelFormat.SetValue(PySpin.PixelFormat_BGR8)
cam.BeginAcquisition()
image_result = cam.GetNextImage()
image_converted = image_result.Convert(PySpin.PixelFormat_BGR8)
#  Convert the Image object to RGB array
width = image_result.GetWidth()
height = image_result.GetHeight()
rgb_array = image_converted.GetData()
rgb_array = rgb_array.reshape(height, width, 3)

The following shows, how this could be done:下面显示了如何做到这一点:

### Set Pixel Format to RGB8 ###
node_pixel_format = 
PySpin.CEnumerationPtr(nodemap.GetNode('PixelFormat'))

if not PySpin.IsAvailable(node_pixel_format) or not PySpin.IsWritable(node_pixel_format):
   print('Unable to set Pixel Format to RGB8 (enum retrieval). Aborting...')
node_pixel_format_RGB8 = node_pixel_format.GetEntryByName('RGB8')
if not PySpin.IsAvailable(node_pixel_format_RGB8) or not PySpin.IsReadable(node_pixel_format_RGB8):
   print('Unable to set Pixel Format to RGB8 (entry retrieval). Aborting...')

pixel_format_RGB8 = node_pixel_format_RGB8.GetValue()
node_pixel_format.SetIntValue(pixel_format_RGB8)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM