В моем проекте на python я использовал Ethernet-камеры Basler GigE Vision, поскольку pylon не поддерживает python, тогда я использовал pypylon.pylon wrapper , чтобы открыть его в python.Это мой класс, чтобы открыть камеру, но после создания исполняемого файла я получаю ошибки при ее открытии. Я использовал spec-файл для работы с pyinstaller. Я получаю следующие ошибки:
import pypylon.pylon as py
import numpy as np
class PylonVideoReader:
def __init__(self, deviceName=None):
self.deviceName = deviceName
tlfactory = py.TlFactory.GetInstance()
if not self.deviceName is None:
deviceInfoList = tlfactory.EnumerateDevices()
deviceIndex = None
for i in range(len(deviceInfoList)):
if self.deviceName == deviceInfoList[i].GetUserDefinedName():
deviceIndex = i
break
if deviceIndex is None:
print("Device: {} not found please ensure that it is "
"connected".format(self.deviceName))
exit()
else:
# Create new camera
self.camera = py.InstantCamera(tlfactory.CreateDevice(
deviceInfoList[deviceIndex]))
else:
# Create new camera
self.camera = py.InstantCamera(tlfactory.CreateFirstDevice())
# Open camera
self.camera.Open()
# Set max number of frame buffers
self.camera.MaxNumBuffer = 50
# Initialize the image format converter
self.formatConverter = py.ImageFormatConverter()
# Set output pixel format to BGR8 for opencv
self.formatConverter.OutputPixelFormat = py.PixelType_BGR8packed
# Start grabbing process
self.camera.StartGrabbing(py.GrabStrategy_LatestImageOnly)
# Grab a first image to get its size
grabResult = self.camera.RetrieveResult(10000)
# Stop grabbing process
# self.camera.StopGrabbing()
# Get dimensions of image
self.frameWidth = grabResult.GetWidth()
self.frameHeight = grabResult.GetHeight()
def get(self, code):
if code == 3:
return self.frameWidth
elif code == 4:
return self.frameHeight
else:
print("{} is not a known property code".format(code))
def read(self):
# try:
# Start grabing process
# self.camera.StartGrabbing(py.GrabStrategy_LatestImageOnly)
# Grab an image
grabResult = self.camera.RetrieveResult(10000)
# Stop grabing process
# self.camera.StopGrabbing()
# Get dimensions of image
self.frameWidth = grabResult.GetWidth()
self.frameHeight = grabResult.GetHeight()
if grabResult.GrabSucceeded():
# Convert Grab result from YUV422 to BGR8
pylonImage = self.formatConverter.Convert(grabResult)
# Convert pylon image to opencv image
# image = np.frombuffer(bytearray(pylonImage.GetBuffer()), np.uint8)
image = np.asarray(bytearray(pylonImage.GetBuffer()), np.uint8)
image = image.reshape(self.frameHeight, self.frameWidth, 3)
return (True, image)
# except :
return (False, None)
def release(self):
self.camera.StopGrabbing()
self.camera.Close()
основной код:
if __name__ == "__main__":
cap = PylonVideoReader("Admin1")
cv2.namedWindow("Test1", cv2.WINDOW_NORMAL)
while True:
ret, image = cap.read()
if ret:
cv2.imshow("Test1", image)
if cv2.waitKey(1) % 256 == ord('q'):
break
Traceback (последний вызовпоследнее): файл "site-packages \ pypylon \ pylon.py", строка 42, в файле swig_import_helper
Файл "importlib__init__.py", строка 126, в файле import_module "", строка 994, в файле _gcd_import "", строка971, в _find_and_load File "", строка 953, в _find_and_load_unlocked ModuleNotFoundError: нет модуля с именем 'pypylon._pylon'
Во время обработки вышеуказанного исключения произошло другое исключение:
Traceback (последний вызов был последним): файл "MainGuiLogic.py", строка 18, в файле "c: \ programdata \ anaconda3 \ lib \ site-packages \ PyInstaller \ loader \ pyimod03_importers.py", строка 631, в файле exec_moduleexec (байт-код, модуль. dict ) Файл "PylonVideoReader.py", строка 1, в файле "c: \ programdata \ anaconda3 \ lib \ site-packages \ PyInstaller \ loader \ pyimod03_importers.py", строка631, в exec_module exec (байт-код, модуль. dict ) Файл "site-packages \ pypylon \ pylon.py", строка 45, в файле "site-packages \ pypylon \ pylon.py", строка 44, в swig_import_helper
Файл "importlib__init__.py", строка 126,в файле import_module "c: \ programdata \ anaconda3 \ lib \ site-packages \ PyInstaller \ loader \ pyimod03_importers.py", строка 714, в модуле load_module = loader.load_module (полное имя) ModuleNotFoundError: нет модуля с именем 'pypylon._genicam ' [4300] Не удалось выполнить скрипт MainGuiLogic [4300] ПОГРУЗЧИК: ОК.[4300] ПОГРУЗЧИК: Очистка интерпретатора Python.