-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlaser_Camera.py
38 lines (23 loc) · 1.05 KB
/
Blaser_Camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
import cv2
import numpy as np
from pypylon import pylon
class Camera:
def __init__(self, camera_id, camera_matrix_path, camera_distortion_path):
self.camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
self.camera_matrix = np.loadtxt(camera_matrix_path)
self.camera_distortion = np.loadtxt(camera_distortion_path)
self.camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
self.converter = pylon.ImageFormatConverter()
# converting to opencv bgr format
self.converter.OutputPixelFormat = pylon.PixelType_BGR8packed
self.converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
def get_frame(self):
frame = self.camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
if frame.GrabSucceeded():
image = self.converter.Convert(frame)
image = image.GetArray()
else:
raise IOError("Camera did not return a frame")
frame.Release()
return image