Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pythonによる工業用カメラ画像取得事例

OHNO
August 08, 2020

 Pythonによる工業用カメラ画像取得事例

OHNO

August 08, 2020
Tweet

More Decks by OHNO

Other Decks in Programming

Transcript

  1. Pythonプログラム1/3 from pypylon import pylon from pypylon import genicam import

    sys import cv2 import numpy as np width = 2044 height = 1536 img1 = np.zeros((height, width, 1), np.uint8) countOfImagesToGrab = 10 exitCode = 0 try: camera =pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice()) camera.Open() print("Using device ", camera.GetDeviceInfo().GetModelName()) new_width = camera.Width.GetValue() - camera.Width.GetInc()
  2. Pythonプログラム2/3 if new_width >= camera.Width.GetMin(): camera.Width.SetValue(new_width) camera.MaxNumBuffer = 5 while

    True: camera.StartGrabbingMax(1) while camera.IsGrabbing(): grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException) if grabResult.GrabSucceeded(): img = grabResult.Array cv2.imshow("img",img) key=cv2.waitKey(1) else: print("Error: ", grabResult.ErrorCode, grabResult.ErrorDescription) if key=='q’: break grabResult.Release()
  3. Pythonプログラム3/3 camera.Close() except genicam.GenericException as e: # Error handling. print("An

    exception occurred.") print(e.GetDescription()) exitCode = 1 sys.exit(exitCode)