Created
May 7, 2019 05:53
Star
You must be signed in to star a gist
Harvester & OpenCV DisplayImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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