EasyPySpin
EasyPySpin copied to clipboard
Bit Depth v. frame.dtype
Hello, a question on bit depth and word sizes from the "capture.read" method in EasyPySpin
cap = EasyPySpin.VideoCapture(0) print("bit depth ", cap.get_pyspin_value("AdcBitDepth"))
gives a value of "2" which SEEMS to correspond to AdcBitDepth_Bit12 per the Spinnaker SDK enums here: http://softwareservices.flir.com/Spinnaker/latest/group___camera_defs__h.html#ggab01f909b0beb1f066113dfa20f9534bca9b373f9c37c70d4bf635feb740bad119
Capturing the data and checking the dtype of the numpy array returned:
ret, frame = capture.read() print("Initial Frame dtype BEFORE color conversion", frame.dtype) frame = cv2.cvtColor(frame, cv2.COLOR_BayerBG2BGR) print("Initial Frame dtype AFTER color conversion", frame.dtype)
In either case (before and after cvtColor) frame.dtype = uint8
It seems that a bit depth greater than 8 would force the capture to be something like uint16. Otherwise, possibly throwing away resolution...? This is for a BFS-U3-31S4 FLIR camera. I have not attempted to change the bit depth. Not sure if there is a setting via EasyPySpin that could capture the higher resolution? Thanks in advance for any help, EasyPySpin is a very useful abstraction for Python/OpenCV users!
Hi @randyg3000 !
gives a value of "2" which SEEMS to correspond to AdcBitDepth_Bit12 per the Spinnaker SDK enums here: http://softwareservices.flir.com/Spinnaker/latest/group___camera_defs__h.html#ggab01f909b0beb1f066113dfa20f9534bca9b373f9c37c70d4bf635feb740bad119
Yes, true. EasyPySpin returns an enum value as a number, as the original PySpin does.
It seems that a bit depth greater than 8 would force the capture to be something like uint16.
As a disclaimer, I'm NOT a developer of SpinnakerSDK and PySpin, so I'm not sure, but I will explain my thoughts. If we set a high ADC bit depth, the camera reads electric signals of the image sensor with high ADC bit depth. But, after reading the signals, it is converted to image data at 8-bit (uint8). So the dtype of your numpy array data becomes uint8. To get a high-bit depth image, you should change PixelFormat. You will get a uint16 image by using the following code.
import EasyPySpin
cap = EasyPySpin.VideoCapture(0)
print(cap.get_pyspin_value("PixelFormat")) # >>> 4
# Default value is 4 in my case (BFS-U3-23S3C)
# 4 is BayerRG8
cap.set_pyspin_value("PixelFormat", "BayerRG16")
print(cap.get_pyspin_value("PixelFormat")) # >>> 8
ret, frame = cap.read()
print(frame.dtype) # >>> uint16
You can check PixelFormat enum from here. http://softwareservices.flir.com/Spinnaker/latest/group___camera_defs__h.html#gabd5af55aaa20bcb0644c46241c2cbad1