#############################################################
#
# FILE: SimpleCircNumpy.py
# DATE: 04/28/2022
# COMPANY: BitFlow, Inc.
# DESCRIPTION: A simple example of capturing data
# into a Numpy array from a single frame grabber
# board.
#
#############################################################
import platform
if(platform.system() == 'Windows'):
import sys
import msvcrt
if (sys.version_info.major >= 3 and sys.version_info.minor >= 8):
import os
#Following lines specifying, the location of DLLs, are required for Python Versions 3.8 and greater
os.add_dll_directory("C:\BitFlow SDK 6.5\Bin64")
os.add_dll_directory("C:\Program Files\CameraLink\Serial")
import BFModule.BufferAcquisition as Buf
import cv2
import numpy as np
import time
from datetime import datetime
# The main function
def main():
numBuffers = 10
print('Circular Acquisition Example')
print('---------------------------------')
#CirAq = Buf.clsCircularAcquisition(Buf.ErrorMode.ErIgnore)
CirAq = Buf.clsCircularAcquisition()
#Call Open board function by showing the Board select dialog
CirAq.Open()
#CirAq.Open(0) # Use this to open board 0 without displaying the board select dialog
#Setup the buffers using the numpy array
BufArray = CirAq.BufferSetup(numBuffers)
#Setup acquisition using the default options
CirAq.AqSetup(Buf.SetupOptions.setupDefault)
cv2.namedWindow("Image Window")
#Start Acquisition
CirAq.AqControl(Buf.AcqCommands.Start, Buf.AcqControlOptions.Wait)
print("Acquisition Started.")
print("\nHit q to exit.\n")
keepUpdating = True
while keepUpdating:
try:
if(CirAq.GetAcqStatus().Start == True):
CurBuf = CirAq.WaitForFrame(1000)
#converting to 16 bits, as OpenCV imshow does not support uint32 images
img = BufArray[CurBuf.BufferNumber].astype(np.uint16)
cv2.imshow("Image Window", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
keepUpdating = False
break
except Exception as e:
print(e)
pass
# destroy the OpenCV image window
cv2.destroyAllWindows()
#Cleanup acquisition
CirAq.AqCleanup()
#Free allocated resources
CirAq.BufferCleanup()
#Close the board
CirAq.Close()
if __name__ == "__main__":
main()