Last active
January 13, 2024 08:50
-
-
Save ks00x/af520dbba1ada0fbdc5e5d6582b22e55 to your computer and use it in GitHub Desktop.
minimal python code to read out the raw data from an infiray p2pro camera and convert it to temperature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also made a version with a class definition that can be used in other projects directly:
https://gist.github.com/ks00x/9003fc0e1103bb2a4ecc690ab855633e