Skip to content

Instantly share code, notes, and snippets.

@immengineer
Created May 7, 2019 05:53
Show Gist options
  • Save immengineer/d071831e4553bbd885a542212509ee55 to your computer and use it in GitHub Desktop.
Save immengineer/d071831e4553bbd885a542212509ee55 to your computer and use it in GitHub Desktop.
Harvester & OpenCV DisplayImage
from harvesters.core import Harvester
import sys
import traceback
import cv2
def main():
h = Harvester()
h.add_cti_file('C:/Program Files/JAI/SDK/bin/JaiUSB3vTL.cti')
h.update_device_info_list()
ia = h.create_image_acquirer(0)
ia.device.node_map.PixelFormat.value = 'BayerRG8'
ia.device.node_map.TestPattern = 'HorizontalColorBar'
try:
ia.start_image_acquisition()
i = 0
done = False
while not done:
with ia.fetch_buffer() as buffer:
img = buffer.payload.components[0].data
img = img.reshape(buffer.payload.components[0].height, buffer.payload.components[0].width)
img_copy = img.copy()
img_copy = cv2.cvtColor(img, cv2.COLOR_BayerRG2RGB)
cv2.namedWindow("window", cv2.WINDOW_KEEPRATIO | cv2.WINDOW_NORMAL)
cv2.imshow("window", img_copy)
fps = ia.statistics.fps
print("FPS: ", fps)
if cv2.waitKey(10) == ord('q'):
done = True
print('break')
i = i + 1
except Exception as e:
traceback.print_exc(file=sys.stdout)
finally:
ia.stop_image_acquisition()
ia.destroy()
cv2.destroyAllWindows()
print('fin')
h.reset()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment