7

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? 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)
ZF007
  • 3,708
  • 8
  • 29
  • 48
Pedram
  • 97
  • 3
  • 14

2 Answers2

5

I had the same issue but with a Blackfly S camera over USB. 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)
loose_bits
  • 51
  • 4
  • I am trying to avoid image_result.Convert() during data collection since it takes time to do the conversion. I am saving my data as 1D vector of "raw" data. My camera is 12bit but I get 8bit numpy vector. The length of the vector is heightXwidthX1.5 since you need 1.5 bytes to encode 12 bit integer. The question is how would one convert the vector of 8bit integers to a vector of 12bit integers. – Valentyn Jun 17 '20 at 14:51
2

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)
Martijn van Wezel
  • 1,120
  • 14
  • 25
Pedram
  • 97
  • 3
  • 14