-
-
Save ks00x/af520dbba1ada0fbdc5e5d6582b22e55 to your computer and use it in GitHub Desktop.
| import cv2 | |
| import numpy as np | |
| ''' | |
| with info from , check out: | |
| https://www.eevblog.com/forum/thermal-imaging/infiray-and-their-p2-pro-discussion/200/ | |
| https://github.com/leswright1977/PyThermalCamera/blob/main/src/tc001v4.2.py | |
| I did create a seperate conda env for this project on Windows: | |
| conda create -n p2pro python | |
| activate p2pro | |
| pip install opencv-python pyusb pyaudio ffmpeg-python | |
| tested with cv2 version 4.8.0 | |
| ''' | |
| id = 0 # the p2pro camera may have a higher id (1,2..) | |
| cap = cv2.VideoCapture(id) | |
| cap.set(cv2.CAP_PROP_CONVERT_RGB, 0) # do not create rgb data! | |
| i = 0 | |
| while(True): | |
| # Capture frame-by-frame | |
| ret, frame = cap.read() | |
| # frame is a 1D numpy array of 8bit integers, we need to reshape it | |
| # 1. index is the upper/lower image part of the video stream | |
| # the 4. index is to address the 2 bytes of the 16bit data | |
| frame = np.reshape(frame[0],(2,192,256,2)) | |
| raw = frame[1,:,:,:].astype(np.intc) # select only the lower image part | |
| raw = (raw[:,:,1] << 8) + raw[:,:,0] # assemble the 16bit word | |
| temp = raw/64 - 273.2 # convert to Celsius scale | |
| i += 1 | |
| if i%20 == 0 : | |
| print(f"min = {temp.min():1.4}, max = {temp.max():1.4}, avg = {temp.mean():1.4},") | |
| brightness = 0.01 | |
| contrast = 0.95 | |
| # values scaled to [0,1] range | |
| cv2.imshow('frame',(temp-temp.min())/(temp.max()-temp.min()) * contrast + brightness) | |
| #Waits for a user input to quit the application | |
| if cv2.waitKey(1) & 0xFF == ord('q'): | |
| break | |
| cap.release() | |
| cv2.destroyAllWindows() |
Line 28 is throwing ValueError: cannot reshape array of size 768 into shape (2,192,256,2).
Interestingly, frame.shape will print (384, 256, 3), so I presume the frame has been converted to RGB/BGR. Any idea what could cause this?
If the (in Windows required) cv2.CAP_DSHOW is omitted in line 18, the resulting array will have a shape of (1, 460800), which, to my mind, is not a multiple of either 256 and 192. Any help appreciated!
Line 28 is throwing
ValueError: cannot reshape array of size 768 into shape (2,192,256,2). Interestingly,frame.shapewill print(384, 256, 3), so I presume the frame has been converted to RGB/BGR. Any idea what could cause this?If the (in Windows required)
cv2.CAP_DSHOWis omitted in line 18, the resulting array will have a shape of(1, 460800), which, to my mind, is not a multiple of either 256 and 192. Any help appreciated!
could you please try: https://github.com/ks00x/p2proviewer/blob/main/p2profile.py which should work. If it doesn't, you might have modified the file in some way (edited metadata)
I also made a version with a class definition that can be used in other projects directly:
https://gist.github.com/ks00x/9003fc0e1103bb2a4ecc690ab855633e