derricw / pysentech

Python Interface for Sentech USB Cameras
MIT License
5 stars 1 forks source link

Error with pysentech #1

Open Achim123 opened 7 years ago

Achim123 commented 7 years ago

Hello, i have a a problem: sdk: 3.10 and python 3.6.0 # thank you for help !

TestCode:

-*- coding: utf-8

import sys,os sys.path.append('C:\Python36\lib\site-packages\pysentech') from pysentech import SentechSystem os.environ['PATH'] += os.pathsep + 'D:\Open-CV\StandardSDK\Bin\x64' system = SentechSystem('d:/open-cv/StandardSDK') print( system.camera_count()) # this works ! cam = system.get_camera(0) # here the error appears !

C:\Python36\pythonw.exe D:/Open-CV/sentech.py 1 Traceback (most recent call last): File "D:/Open-CV/sentech.py", line 26, in cam = system.get_camera(0) File "C:\Python36\lib\site-packages\pysentech\system.py", line 39, in get_camera return SentechCamera(index, self.dll) File "C:\Python36\lib\site-packages\pysentech\camera.py", line 67, in init self._setup_frame() File "C:\Python36\lib\site-packages\pysentech\camera.py", line 88, in _setup_frame width, height = self.image_shape File "C:\Python36\lib\site-packages\pysentech\camera.py", line 126, in image_shape cwidth, cheight) File "C:\Python36\lib\site-packages\pysentech\camera.py", line 42, in method result = function(cam.handle, *args, **kwargs) OSError: exception: access violation reading 0x000000005B2C0B28 Exception ignored in: <bound method SentechCamera.del of <camera.SentechCamera object at 0x0000026C5A475390>> Traceback (most recent call last): File "C:\Python36\lib\site-packages\pysentech\camera.py", line 286, in del File "C:\Python36\lib\site-packages\pysentech\camera.py", line 282, in release AttributeError: frame

Process finished with exit code 1

derricw commented 7 years ago

Hello! Yes I didn't know that 3.10 had been released. I have only tested with 3.08. I'll take a look at this tonight.

Thanks for the report!

derricw commented 7 years ago

Hello, I was able to reproduce the issue by running it in Python3. I have pushed some changes that should resolve it: https://github.com/derricw/pysentech/commit/e01080e47bed7699cade90b40f30af03e2897fd8

Give it a try and let me know if it works for you.

Achim123 commented 7 years ago

Hello Derric,

thank you four your first help ! i tested my code again with the new version : it's getting better , but not ok ...

-*- coding: utf-8 import sys,os

sys.path.append('C:\Python36\lib\site-packages\pysentech') from pysentechimport SentechSystem os.environ['PATH']+= os.pathsep+ 'D:\Open-CV\StandardSDK\Bin\x64' system= SentechSystem('d:/open-cv/StandardSDK')

print( system.camera_count())

""" Or saved to a file using the SDK's file-saving functions: cmode = c_ushort() cam.StCam_GetBinningSumMode(byref(cmode)) cmode.value """ cam= system.get_camera(0) print(cam.model)

cam.gain = 50 print( cam.image_shape )

frame= cam.grab_frame()

print(frame)

pil_img = frame.as_pil() frame.to_file("d:\test_img.png")

np_img = frame.as_numpy()

output: it seems so that some functions with the frame instance are not working: as_numpy, as_pil, to_file

1 b'STC-MCCM200U3V' (2048, 1088) <pysentech.frame._SentechFrame object at 0x000001E6E46CAEB8> Traceback (most recent call last): File "D:/Open-CV/sentech.py", line 33, in frame.to_file("d:\test_img.png") File "C:\Python36\lib\site-packages\pysentech\frame.py", line 118, in to_file 0): OSError: exception: access violation reading 0x000001E6E7113040

the next text with your example: low_level_cv2.py:

C:\Python36\pythonw.exe D:/Open-CV/examples/low_level_cv2.py DLL loaded! Cameras found: 1 Camera open! Handle: 13856768 Camera image shape: 2048x1088 Failed to set pixel format! Camera pixel format: 4 Camera bits per pixel: 1 Camera bytes per image: 2228224 Traceback (most recent call last): File "D:/Open-CV/examples/low_level_cv2.py", line 111, in array = (c_ubyte int(heightbpi) * OverflowError: The 'length' attribute is too large

Am 28.02.2017 um 06:28 schrieb Derric Williams:

Hello, I was able to reproduce the issue by running it in Python3. I have pushed some changes that should resolve it: e01080e https://github.com/derricw/pysentech/commit/e01080e47bed7699cade90b40f30af03e2897fd8

Give it a try and let me know if it works for you.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/derricw/pysentech/issues/1#issuecomment-282946147, or mute the thread https://github.com/notifications/unsubscribe-auth/AY3QJEDRYcd9JLfj3vDWyCaCBe5pRb3Qks5rg7BqgaJpZM4MNjo1.

derricw commented 7 years ago

It looks like you are using a color camera.

I will take a look at this tonight, but unfortunately I don't have a color camera to test with. It is definitely a problem with the creation of the image array. We may just be able to create a 2048x1088x3 c_ubyte array (and a matching numpy one) to accommodate the color image buffers.

If you open the camera in StCamWare software, are you able to set it to "GRAY8", or some format that only uses 8 bits per pixel? What formats are available?

Achim123 commented 7 years ago

Hello Derric, thanks for your answer. yes , you are right, i use a color-camera. It is not possible to set GRAY8 in the StCamWare software.

thanks for your help ! Joachim

Am 28.02.2017 um 23:29 schrieb Derric Williams:

It looks like you are using a color camera. Try setting the pixel format to "Mono8". I will take a look at this tonight, but unfortunately I don't have a color camera to test with.

If you open the camera in StCamWare software, are you able to set it to "GRAY8"?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/derricw/pysentech/issues/1#issuecomment-283182116, or mute the thread https://github.com/notifications/unsubscribe-auth/AY3QJFzx1h4n9IoGSgzGwFqGRogR8Cr6ks5rhJ_ggaJpZM4MNjo1.

derricw commented 7 years ago

Hey, I still don't have a color camera to test with, but I've added a script that should work. Take a look at low_level_color_cv2.py and let me know if it works. If so I'll try and add support to the high-level interface.

abedtoufik commented 6 years ago

Dear derricw, Thanks for package it's really help. Had error when run the camera.

I have followed all you correction to get in Python 3 and SDK 3.10, knowing that SDK know is in 3.12 version. Using color camera MCA05MUSB3.

tested the low_level_color_cv2.py.

When : cameras_available = dll.StCam_CameraCount(None) print("Cameras found: {}".format(cameras_available))

the error : C:/Users/t.abed/Desktop/sdk_folder Traceback (most recent call last): File "C:/Users/t.abed/Desktop/.PyCharmCE2017.1/cam/CameraSentech.py", line 16, in cameras_available = dll.StCam_CameraCount(None) ValueError: Procedure probably called with too many arguments (4 bytes in excess)

Should i change something in DLL. Thank you in advance.