leswright1977 / PySpectrometer2

The Second Incarnation of the Spectrometer project!
Apache License 2.0
204 stars 24 forks source link

specFunction.py crashes #6

Closed h1t1h closed 1 year ago

h1t1h commented 1 year ago

Spectrometer: Thunder Optics SMA-E connected via USB python: 3.7.3 Programm start: python PySpectrometer2-USB-v1.0.py --device 0

Error message:

Traceback (most recent call last): File "PySpectrometer2-USB-v1.0.py", line 263, in intensity = savitzky_golay(intensity,17,savpoly) File "/home/pi/Python/opencv/specFunctions.py", line 143, in savitzky_golay lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1]) TypeError: unsupported operand type(s) for -: 'list' and 'int'

The problem can be fixed by the follwing code:

` y_new = np.array(y)

firstvals = y_new[0] - np.abs( y_new[1:half_window+1][::-1] - y_new[0] )
lastvals = y_new[-1] + np.abs(y_new[-half_window-1:-1][::-1] - y_new[-1])
y_new = np.concatenate((firstvals, y_new, lastvals))

return np.convolve( m[::-1], y_new, mode='valid')`

But then PySectrometer2-USB-v1.0.py itself crashes with the follwing message:

Traceback (most recent call last): File "PySpectrometer2-USB-v1.0.py", line 327, in <module> spectrum_vertical = np.vstack((messages,cropped, graph)) File "<__array_function__ internals>", line 6, in vstack File "/home/pi/Python/opencv/lib/python3.7/site-packages/numpy/core/shape_base.py", line 282, in vstack return _nx.concatenate(arrs, 0) File "<__array_function__ internals>", line 6, in concatenate ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 800 and the array at index 1 has size 640

Omitting "cropped" in line 327 at least shows, that he spectrometer is handled o.k. (I do see a live spectrum while pointing the device to a light source), but deleting part of the code without being able to assess the consequences is probably not a wise thing to do.

Any hint on how to fix this error is highly apprepciated!

leswright1977 commented 1 year ago

From the portion of the error that says: "the array at index 0 has size 800 and the array at index 1 has size 640" I woudl surmise your camera resolution, is fixed at 640x480 (cv2 library has difficultty setting values for some cameras). The software exptects 800x600.

h1t1h commented 1 year ago

Thank you very much for your feedback. The camera of the SMA-E has a resolution of 1920 x 1080... Even though I probably won't spend more time looking into making the spectrometer work: Please keep up with this great project!