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

2024-03-29 11:42:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从flea3相机(代码为“FL3-U3-32S2C-CS”,显示的是一个彩色相机)获取彩色图像(在我的例子中,rgb或bgr没有区别),但我的代码生成灰度照片。。。下面的代码片段有什么问题?有什么想法吗?在

    #  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)

Tags: 代码imageconvertimgrgbresultwidtharray
2条回答

我也遇到了同样的问题,但是我用的是一个USB接口的Blackfly S摄像头。我必须使用一种特定的格式来实现它。在采集之前,我还设置了相机的像素格式。在

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)

以下是应该如何完成:

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

if not PySpin.IsAvailable(node_pixel_format) or not PySpn.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)

相关问题 更多 >